hdu6944
https://acm.hdu.edu.cn/showproblem.php?pid=6944
题意:
给出一些数字,每次选一个数字减去9,99,999,要求结果大于0,且要求最终每个数字只能出现一次,不能操作的人就输了
考虑每次减去的9,99,999可以转化成9*1,9*11,9*111,一次操作奇数个9,统计共有多少个可以减的9,再判断奇偶性
要记录余数,很巧妙
由于减去后的结果不能是0,也不能是出现过的数字,所以用cnt数组来记录余数出现的次数
eg.b=x/9,c=x%9
因为不能为0,所以cnt[0]置为1,所以只能操作减去(b-1)个9,并且更新cnt[0]++,更新是为了下次碰到余数为0的时候只能操作(b-2)个9
但是这样会出现负数,但是负数也是满足于奇偶的规律的,虽然我不是很理解
#include<stdio.h> #include<algorithm> #include<vector> #include<string.h> //#include<iostream> //using namespace std; //inline void tie0() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } using namespace std; const int maxn=2e5+7; typedef pair<int,int> p; const int d=1e5; const int mod=4933; typedef long long ll; ll a[maxn]; ll cnt[100]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(cnt,0,sizeof(cnt)); cnt[0]=1; ll ans=0; for(int i=1;i<=n;i++) {scanf("%lld",&a[i]); int b=a[i]/9; int c=a[i]%9; ans+=b-cnt[c]; cnt[c]++; } if(ans%2==1) printf("A\n"); else printf("B\n"); } }
浙公网安备 33010602011771号