BestCoder Round #90
1001 Kblack loves flag
太弱只写了这一道水题。
首先这个题面就是,完全不知道它在说什么。开始5mins后我还完全不知道这个题想要表达什么。看了10分钟们终于看出来那个随机数的用意了。原来是就是用随机数来模式输入的数据,可能因为数据量太大,才采用这种方法的。我是第一次见,在这卡了半天。
之后是想用排序然后统计个数的方法,写了半天,发现写的不对,没有头绪。要统计数组中不重复元素的个数是多少,自然想到了map,然后写了一发,上去直接超时。果然STL慢。后来仔细想了一下,sort排好序,一个一个判断,如果和当前的相同则不动,否则计数器加一。分别对x和y做操作就好。然后AC。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int _K=50268147,_B=6082187,_P=100000007;
int _X;
inline int get_rand(int _l,int _r){
_X=((long long)_K*_X+_B)%_P;
return _X%(_r-_l+1)+_l;
}
int n,m,k,seed;
int x[1000006],y[1000006];
void Init(){
scanf("%d%d%d%d",&n,&m,&k,&seed);
_X=seed;
for (int i=1;i<=k;++i){
x[i]=get_rand(1,n);
y[i]=get_rand(1,m);
}
}
bool cmp(int a,int b)
{
return a<b;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
Init();
int i, cnt1 =1,cnt2 = 1,temp;
sort(x+1,x+k+1,cmp);
sort(y+1,y+k+1,cmp);
temp = x[1];
for(i = 1;i<=k;++i){
if(x[i]!=temp){
cnt1++;
temp = x[i];
}
}
temp = y[1];
for(i = 1;i<=k;++i){
if(y[i]!=temp){
cnt2++;
temp = y[i];
}
}
printf("%d %d
",n-cnt1,m-cnt2);
}
return 0;
}
象征性的贴个代码。
还是刷题重要。
先啃DP。