More actions
imported>Unknown No edit summary |
(Repair batch-0003 pages from live compare) |
||
| Line 48: | Line 48: | ||
{ | { | ||
if(test_team | if(test_team[i].maxNum >= test_table.size()) | ||
{ | { | ||
totalcount++; | totalcount++; | ||
for(j = 0; j < test_table.size(); j++) | for(j = 0; j < test_table.size(); j++) | ||
test_team | test_team[i].tableNum.push_back(j+1); | ||
if(test_team | if(test_team[i].maxNum == 2* test_table.size()) | ||
{ | { | ||
totalcount++; | totalcount++; | ||
for(j = 0; j < test_table.size(); j++) | for(j = 0; j < test_table.size(); j++) | ||
test_team | test_team[i].tableNum.push_back(j+1); | ||
} | } | ||
} | } | ||
for(j = 0; j < test_team | for(j = 0; j < test_team[i].maxNum % test_table.size(); j++) | ||
{ | { | ||
test_table | test_table[j].maxNum--; | ||
test_team | test_team[i].tableNum.push_back(test_table[j].Num); | ||
} | } | ||
for(j = 0; j < test_table.size(); j++) | for(j = 0; j < test_table.size(); j++) | ||
{ | { | ||
if(test_table | if(test_table[j].maxNum - totalcount < 0) | ||
check = false; | check = false; | ||
} | } | ||
| Line 83: | Line 83: | ||
for(i = 0; i < test_team.size(); i++) | for(i = 0; i < test_team.size(); i++) | ||
{ | { | ||
sort(test_team | sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end()); | ||
for(j = 0; j < test_team | for(j = 0; j < test_team[i].maxNum; j++) | ||
cout << test_team | cout << test_team[i].tableNum[j] << " "; | ||
cout << endl; | cout << endl; | ||
} | } | ||
| Line 169: | Line 169: | ||
for(i = 0; i < test_team.size(); i ++) | for(i = 0; i < test_team.size(); i ++) | ||
{ | { | ||
if(test_team | if(test_team[i].maxNum > maxtable) | ||
{ | { | ||
check = false; | check = false; | ||
| Line 176: | Line 176: | ||
else | else | ||
{ | { | ||
for(j = 0; j < test_team | for(j = 0; j < test_team[i].maxNum; j++) | ||
{ | { | ||
test_table | test_table[j].maxNum--; | ||
test_team | test_team[i].tableNum.push_back(test_table[j].Num); | ||
} | } | ||
test_team | test_team[i].maxNum = 0; | ||
temp1 = maxtable; | temp1 = maxtable; | ||
for(j = 0; j < temp1; j++) | for(j = 0; j < temp1; j++) | ||
{ | { | ||
if(test_table | if(test_table[j].maxNum == 0) | ||
maxtable--; | maxtable--; | ||
} | } | ||
| Line 200: | Line 200: | ||
for(i = 0; i < test_team.size(); i++) | for(i = 0; i < test_team.size(); i++) | ||
{ | { | ||
sort(test_team | sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end()); | ||
for(j = 0; j < test_team | for(j = 0; j < test_team[i].tableNum.size(); j++) | ||
cout << test_team | cout << test_team[i].tableNum[j] << " "; | ||
cout << endl; | cout << endl; | ||
} | } | ||
| Line 236: | Line 236: | ||
return 0; | return 0; | ||
} | } | ||
Latest revision as of 00:29, 27 March 2026
오류 버전(통과는 됐음)
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
struct table
{
int Num;
int maxNum;
};
struct team
{
int Num;
int maxNum;
vector<int> tableNum;
};
int tableNum, teamNum, i, j, k, l;
team temp1;
table temp2;
vector<table> test_table;
vector<team> test_team;
bool compare_table(const table & a,const table & b)
{
return a.maxNum > b.maxNum;
}
bool compare_team_max(const team & a,const team & b)
{
return a.maxNum > b.maxNum;
}
bool compare_team_num(const team & a,const team & b)
{
return a.Num < b.Num;
}
void process()
{
int totalcount = 0;
bool check = true;
sort(test_table.begin(),test_table.end(), compare_table);
sort(test_team.begin(), test_team.end(), compare_team_max);
for(i = 0; i < test_team.size(); i ++)
{
if(test_team[i].maxNum >= test_table.size())
{
totalcount++;
for(j = 0; j < test_table.size(); j++)
test_team[i].tableNum.push_back(j+1);
if(test_team[i].maxNum == 2* test_table.size())
{
totalcount++;
for(j = 0; j < test_table.size(); j++)
test_team[i].tableNum.push_back(j+1);
}
}
for(j = 0; j < test_team[i].maxNum % test_table.size(); j++)
{
test_table[j].maxNum--;
test_team[i].tableNum.push_back(test_table[j].Num);
}
for(j = 0; j < test_table.size(); j++)
{
if(test_table[j].maxNum - totalcount < 0)
check = false;
}
if(check == false)
break;
sort(test_table.begin(),test_table.end(), compare_table);
}
if(check)
{
cout << "1" << endl;
sort(test_team.begin(), test_team.end(), compare_team_num);
for(i = 0; i < test_team.size(); i++)
{
sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end());
for(j = 0; j < test_team[i].maxNum; j++)
cout << test_team[i].tableNum[j] << " ";
cout << endl;
}
}
else
cout << "0" << endl;
}
int main()
{
while(true)
{
cin >> teamNum >> tableNum;
if( tableNum == 0 && teamNum == 0)
break;
for(i = 0; i < teamNum;i++)
{
temp1.Num = i + 1;
cin >> temp1.maxNum;
test_team.push_back(temp1);
}
for(i = 0; i < tableNum; i++)
{
temp2.Num = i + 1;
cin >> temp2.maxNum;
test_table.push_back(temp2);
}
process();
test_team.clear();
test_table.clear();
}
return 0;
}
수정판
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
struct table
{
int Num;
int maxNum;
};
struct team
{
int Num;
int maxNum;
vector<int> tableNum;
};
int tableNum, teamNum, i, j, k, l;
team temp1;
table temp2;
vector<table> test_table;
vector<team> test_team;
bool compare_table(const table & a,const table & b)
{
return a.maxNum > b.maxNum;
}
bool compare_team_max(const team & a,const team & b)
{
return a.maxNum > b.maxNum;
}
bool compare_team_num(const team & a,const team & b)
{
return a.Num < b.Num;
}
void process()
{
int maxtable = test_table.size();
int temp1;
bool check = true;
sort(test_table.begin(),test_table.end(), compare_table);
sort(test_team.begin(), test_team.end(), compare_team_max);
for(i = 0; i < test_team.size(); i ++)
{
if(test_team[i].maxNum > maxtable)
{
check = false;
break;
}
else
{
for(j = 0; j < test_team[i].maxNum; j++)
{
test_table[j].maxNum--;
test_team[i].tableNum.push_back(test_table[j].Num);
}
test_team[i].maxNum = 0;
temp1 = maxtable;
for(j = 0; j < temp1; j++)
{
if(test_table[j].maxNum == 0)
maxtable--;
}
sort(test_table.begin(),test_table.end(), compare_table);
}
}
if(check)
{
cout << "1" << endl;
sort(test_team.begin(), test_team.end(), compare_team_num);
for(i = 0; i < test_team.size(); i++)
{
sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end());
for(j = 0; j < test_team[i].tableNum.size(); j++)
cout << test_team[i].tableNum[j] << " ";
cout << endl;
}
}
else
cout << "0" << endl;
}
int main()
{
while(true)
{
cin >> teamNum >> tableNum;
if( tableNum == 0 && teamNum == 0)
break;
for(i = 0; i < teamNum;i++)
{
temp1.Num = i + 1;
cin >> temp1.maxNum;
test_team.push_back(temp1);
}
for(i = 0; i < tableNum; i++)
{
temp2.Num = i + 1;
cin >> temp2.maxNum;
test_table.push_back(temp2);
}
process();
test_team.clear();
test_table.clear();
}
return 0;
}