WOJ1022-Competition of Programming

来源:互联网 发布:剑灵狂三捏脸数据 编辑:程序博客网 时间:2024/06/06 06:54

There are many good reasons for participating in programming contests. You can have fun while you improve both your programming

skills and job prospects in the bargain. From somewhere in this vein arises TopCoder, a company which uses programming contests as a
tool to identify promising potential employees and provides this information to its clients.

The format of TopCoder contests is evolving quickly as they hunt for the most appropriate business model. Preliminary rounds are
held over the web, with the final rounds of big tournaments held on site. Each of these rounds shares the same basic format. The coders
are divided into ?rooms? where they compete against the other coders. Each round starts with a coding phase of 75?80 minutes where the
contestants do their main programming. The score for each problem is a decreasing function of the time from when it was first opened to
when it was submitted. There is then a 15-minute challenge phase where coders get to view the submissions from other contestants in their
room and try to find bugs. Coders earn additional points by submitting a test case that breaks another competitor?s program. There is no
partial credit for incorrect solutions. Is it very interesting and exciting for participating in TopCoder and you just want to participate
it right now?
Now, WOJ (Wuhan University Online Judge) development group will introduce the TopCoder contest format into WOJ. Of course, there
will be something different from TopCoder and we will set some new regulations into WOJ?s TopCoder. Here is one of these regulations: in
the coding phase, we will set the finish time limit T and penalty C for each problem. If you don?t solve the i-th problem in the finish time
limit , your penalty will be added by. Note that the penalty here is completely different from the penalty in ACM. The penalty in WOJ?s
TopCoder is a value set by us and is be independent of the problem solving time.
Assume that you are a genius in programming and it takes only one time unit for you to solve one problem whatever the problem is.
Now, there are N problems in WOJ?s TopCoder contest and the finish time limit and penalty of each problem is given, please write a program
to calculate minimum penalty you will get.

输入格式

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number
of test cases.

The first line of each test case contains only one integer N (1 <= N <= 3000) which specify the total problem numbers. The next N lines each contains the description for one problem, the first integer T (1 <= T <= 3000) specifying the finish time limit and the second integer C
(1 <= C <= 50000) specifying the penalty.

输出格式

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting

from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, print one integer, the minimum penalty described as above.

样例输入

231 53 23 431 52 22 4

样例输出

Case 1:0Case 2:2

贪心

#include <iostream>  #include <cstdio>  #include <sstream>  #include <cstring>  #include <string>  #include <cmath>#include <algorithm> using namespace std;  const int MaxN = 3001;  struct Node {      int t, c;      bool operator < (const Node &tmp) const {          return c > tmp.c;      }  };  Node node[MaxN];  int n;  bool vis[MaxN];    int gao()  {      int res = 0;memset(vis, false, sizeof(vis));      for(int i = 0; i < n; i++){          bool ok = false;for(int j= node[i].t; j >= 1; j--) {              if(!vis[j]) {                  vis[j] = true;                  ok = true;                  break;              }          }          if(!ok) res += node[i].c;      }      return res;  }    int main()  {      int t;      scanf("%d", &t);      int ans = 1;      while(1 == scanf("%d", &n)){          if(ans > 1) puts("");          printf("Case %d:\n", ans++);          for(int i = 0; i < n; i++)            scanf("%d %d", &node[i].t, &node[i].c);          sort(node, node + n);printf("%d\n", gao());    }      return 0;  }  


原创粉丝点击