2013
12-04

# A Contesting Decision

Judging a programming contest is hard work, with demanding contestants, tedious decisions, and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.

Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.

Scoring

There are two components to a team’s score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.

So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.

The winner is the team that solves the most problems. If teams tie for solving the most problems, then the winner is the team with the fewest penalty points.

For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.

Line 1 <nTeams>
Line 2-n+1 <Name> <p1Sub> <p1Time> <p2Sub> <p2Time> … <p4Time>

The first element on the line is the team name, which contains no whitespace. Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.

The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.

4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80

Penguins 3 475

#include <iostream>
#include <string>
using namespace std;
struct Team
{
string Name;
int C,P; //题目数，罚时
Team():C(0),P(0){}
Team operator=(const Team& rhs)
{
Name = rhs.Name;
C = rhs.C;
P = rhs.P;
return *this;
}
};
bool operator<(const Team& lhs,const Team& rhs)
{
if(lhs.C != rhs.C) return lhs.C>rhs.C; //题目数从大到小
else return lhs.P<rhs.P; //罚时从小到大
}
ostream& operator<<(ostream& out,const Team& lhs)
{
out<<lhs.Name<<' '<<lhs.C<<' '<<lhs.P;
return out;
}
int main()
{
int N;
int S[4],T[4]; //提交的次数，AC的时间
while(cin>>N)
{
Team best;
while(N--)
{
Team tmp;
cin>>tmp.Name;
for(int i=0;i<4;++i)
{
cin>>S[i]>>T[i];
if(T[i])
{
++tmp.C;
tmp.P += (T[i]+(S[i]-1)*20);
}
}
if(tmp<best) best = tmp;
}
cout<<best<<endl;
}
return 0;
}

1. 这道题这里的解法最坏情况似乎应该是指数的。回溯的时候
O(n) = O(n-1) + O(n-2) + ….
O(n-1) = O(n-2) + O(n-3)+ …
O(n) – O(n-1) = O(n-1)
O(n) = 2O(n-1)

3. [email protected]

4. “再把所有不和该节点相邻的节点着相同的颜色”，程序中没有进行不和该节点相邻的其他节点是否相邻进行判断。再说求出来的也不一样是颜色数最少的

5. 有限自动机在ACM中是必须掌握的算法，实际上在面试当中几乎不可能让你单独的去实现这个算法，如果有题目要用到有限自动机来降低时间复杂度，那么这种面试题应该属于很难的级别了。