হুররে এবার তাহলে তুমি কন্টেস্ট স্কোরবোর্ড পরিচালনা করার দায়িত্ব পেলে । ডিশিয়া ডিশিয়া । কোনো কন্টেস্টেন্ট যদি এবার তোমার সাথে দাদাগিরি করে তাহলে তাকে বলবা কুইট্টালবাম , মাইরালবাম , খাইয়ালবাম । তুই আমার লগে দাদাগিরি দেখাইছত ক্যারে ? ক্যারে ক্যারে ? এবার ল্যাও ঠ্যালা । যাওকগা এবার তাহলে প্রব্লেমে ফিরে আসা যাক । Lets Back to the problem .
!! Warning : To Solve The Problem Without Watching Solution You Need to Read the Full Post !!
Clearance :
Here you are the Contest Scoreboard Maintainer . You have to maintain / build such a Scoreboard that fulfill the following Requirements .
i) You are to Design ( More Precisely SORT ) the Scoreboard in such a way that the Teams who solved maximum number of problems appears at the top position of the Scoreboard. ( If team 1 solved 2 problems and team 2 solved 3 problems then team 2 will be First & team 1 will be Second.)
ii) If Two / More Teams solved maximum number of problems then they will be SORT according to the Consumption of Less Time . ( If both team 1 & 2 solved 2 problems but 1 takes 10 & 2 takes 20 minutes to Solve then team 1 will be the team 1 will be first & team 2 will be Second .)
iii) If Two / More Teams solved maximum number of problems with the same Time then they will be SORT according to the Increasing Team Number . ( If team 1 & team 2 both solved 2 problems with the consumption of 10 minutes then team 1 will be First & team 2 will be Second . )
Algorithm :
You just need to SORT the List ( Team ID , Number of Solved Problems, Total Run Time. Yes It can be done by using Structure . ) maintaining above's Requirements .
How To Do :
1 . Take the Team Id in an array only once ( No multiple ID can't be in the list .)
2. If the Verdict ' I ' ( i.e. Incorrect Submission) then Store/Add the Penalty times For that Problem For that Team.
3. If the Verdict ' C ' ( i.e. Correct Submission) then increase the " Number Of Problems Solved " for that Team , Flag this problem as " Solved " by that team ( If the Correct or Incorrect Submission Verdict Occurs after Solving for the Respective Problem then It will not Count as a Valid Submission. After Solving. " That Means after Getting ' C ' verdict " for that problem for that Team. ) Then Add the total Penalty Times For that problem For that Team with the Time the Team takes to solve that problem .
4. Create an Structure Array and Enter Team Id, Total Solved Problems, Total Time Consumption for that Team.
5. Now SORT it according to the Requirements as stated above in the Clearance Section .
6. To SORT the Structure Array you need to Create a Compare Function that will SORT the Array According to you Requirements .
7. In the Compare Function you have to put the Requirements as stated above Clearly .
***Done !! Did You Solve it ??***
Tip :
There you may Face an Usual Problem while taking the Inputs . Take the input lines as a String . Then through
sscanf(string name , "format specifiers ( %d , %d, %d, %c.) ". For this problem :
Here ' buffer ' is the String Name . cid = Team Id, prob = Problem Number, Time = Given Time, verdict = Result ( I , C , R , E , U ). If you found a ' verdict ' with Last Three You can ignore these as Those can make any Changes in you Scoreboard .sscanf(buffer,"%d %d %d %c", &cid, &prob, &time, &verdict);
========================== Hope You Solved It ==========================
Code :
#include<bits/stdc++.h>
using namespace std;
struct data{
int id, solved, penalty;
};
bool cmp(data a, data b) // Compare Function
{
if(a.solved==b.solved)
{
if(a.penalty==b.penalty)
{
return a.id<b.id;
}
else return a.penalty<b.penalty;
}
else return a.solved>b.solved;
}
int main()
{
int test;
scanf("%d",&test);
getchar();
getchar();
int probsolved[105], ptime[105], store[105], contprob[105][11];
bool contid[105], issolved[105][11];
while(test--)
{
memset(probsolved,0,sizeof(probsolved));
memset(issolved,false,sizeof(issolved));
memset(contprob,0,sizeof(contprob));
memset(store,0,sizeof(store));
memset(ptime,0,sizeof(ptime));
memset(contid,false,sizeof(contid));
int cid, prob, time;
char verdict;
int cnt = 0;
char buffer[100];
while(gets(buffer) && strlen(buffer)>0)
{
//if(cid==0) break;
sscanf(buffer,"%d %d %d %c", &cid, &prob, &time, &verdict);
if(!contid[cid])
{ contid[cid] = true; store[cnt] = cid; cnt++; }
if(verdict=='R' || verdict=='U' || verdict=='E') continue;
if(verdict=='C' && !issolved[cid][prob])
{
probsolved[cid]++;
ptime[cid] = ptime[cid] + time + contprob[cid][prob];
issolved[cid][prob] = true;
}
else if(verdict=='I' && !issolved[cid][prob])
{
contprob[cid][prob] = contprob[cid][prob] + 20;
}
//cout<<"print = "<<cid<<' '<<probsolved[cid]<<' '<<ptime[cid]<<endl;
}
data man[150];
for(int i=0; i<cnt; i++)
{
if(contid[store[i]])
{
//cout<<store[i]<<' '<<probsolved[i]<<' '<<ptime[i]<<endl;
man[i].id = store[i];
man[i].solved = probsolved[store[i]];
man[i].penalty = ptime[store[i]];
}
}
sort(man,man+cnt, cmp); //Calling Of Compare Function
for(int i=0; i<cnt; i++)
cout<<man[i].id<<' '<<man[i].solved<<' '<<man[i].penalty<<endl;
if(test) printf("\n");
}
return 0;
}
=>Question or Need Help ?? Leave a Comment .
No comments:
Post a Comment