题目
http://www.ioi2009.org/GetResource?id=1271
分析
题目难度不高,有两点注意:
坑如样例。关于排名,题目中这样说:
The final standings of the competition list the contestants in descending order of their scores. In case of a tie, among the tied contestants, those who have solved more tasks will be listed ahead of those who have solved fewer tasks. In case of a tie by this criterion as well, the contestants with equal results will be listed in ascending order of their IDs.也就是说,这道题目对于排名的要求有三点:
- 首先按照分数排名
- 如果分数相同,按照通过题目数量排名
- 如果分数和通过题目数量都相同,按照ID排名
我第一次看到一个,然后又看到一个,最后发现还漏看一个……
所以:真是考试千万不要相信样例!
另外一个关于优化。
题目数据量其实爆大(2,000*2,000 = 4,000,000个读入),如果对于输入输出不太注意的,很容易最后几个点TLE到甚至3秒。
不可避免的读入优化:
1 template<class T>void read(T &x) 2 { 3 x = 0; 4 int f = 0; 5 char ch = getchar(); 6 while (ch < '0' || ch > '9') 7 { 8 f |= (ch == '-'); 9 ch = getchar(); 10 } 11 while (ch >= '0' && ch <= '9') 12 { 13 x = (x << 1) + (x << 3) + (ch^48); 14 ch=getchar(); 15 } 16 x=f?-x:x; 17 return; 18 }
用Template可以让我们很方便的使用各种数据类型。&x指针让我们可以直接写read(x)。
第八行使得如果读到'-',用f记录正负转换。
至于第十三行就是一堆位运算,相对于乘法肯定快很多。
问号操作:如果f为true,返回-x否则返回x。
程序
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int MAXT = 2000 + 1; 4 int n, t, p, prob[MAXT], phi[MAXT][MAXT], ans[MAXT], pos, cnt[MAXT]; 5 6 template<class T>void read(T &x) 7 { 8 x=0; 9 int f=0; 10 char ch=getchar(); 11 while(ch<'0'||ch>'9') 12 { 13 f|=(ch=='-'); 14 ch=getchar(); 15 } 16 while(ch>='0'&&ch<='9') 17 { 18 x=(x<<1)+(x<<3)+(ch^48); 19 ch=getchar(); 20 } 21 x=f?-x:x; 22 return; 23 } 24 int main() 25 { 26 freopen("poi.in","r",stdin); 27 freopen("poi.out","w",stdout); 28 scanf("%d%d%d",&n,&t,&p); 29 for (int i = 1; i <= n; i++) 30 { 31 for (int j = 1; j <= t; j++) 32 { 33 int solve; 34 read(solve); 35 phi[i][j] = solve; 36 if (!solve) 37 prob[j]++; 38 } 39 } 40 for (int i = 1; i <= n; i++) 41 for (int j = 1; j <= t; j++) 42 { 43 if (phi[i][j]) 44 { 45 ans[i] += prob[j]; 46 cnt[i]++; 47 } 48 } 49 printf("%d ",ans[p]); 50 pos = 1; 51 for (int i = 1; i <= n; i++) 52 { 53 if ((ans[i]>ans[p])||((ans[i]==ans[p])&&cnt[i]>cnt[p])||((ans[i]==ans[p])&&cnt[i]==cnt[p]&&i<p)) 54 { 55 pos++; 56 } 57 } 58 printf("%d ",pos); 59 return 0; 60 }