昊昊爱运动
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
昊昊喜欢运动
他
舍友有
问昊昊第
Input
输入两个数
输入
输入一个数
输入
Output
一共
每一行输出一个数 表示昊昊在第
Sample input and output
Sample Input | Sample Output |
---|---|
5 3 1 2 3 2 2 3 1 4 2 4 1 5 |
3 2 3 |
Source
第七届ACM趣味程序设计竞赛第二场(正式赛)
论打表的重要性,数组出现数字种类的统计
<span style="font-size:24px;color:#3333ff;">#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[2005],ans[2005][2005],f[105]; int main() { int n,m,i,j; while(~scanf("%d %d",&n,&m)) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) { memset(f,0,sizeof(f)); int x=0; </span><span style="font-size:24px;color:#3333ff;">for(j=i;j<=n;j++) { if(!f[a[j]]) { f[a[j]]=1; x++; } ans[i][j]=x; }</span><span style="font-size:24px;color:#ff0000;">//统计一段数组中出现的数的个数,非常优美</span><span style="font-size:24px;color:#3333ff;"> } int q,r,l; scanf("%d",&q); for(int i=1;i<=q;i++) { scanf("%d %d",&l,&r); printf("%d ",ans[l][r]); } } return 0; }</span>