2016弱校联盟十一专场10.7(12点场) E. Training little cats
2016-10-07 17:20
477 查看
题目链接:https://www.bnuoj.com/bnuoj/contest_show.php?cid=8507#problem/101989
题意:就是给你一n只狗,一开始每只狗的碗有0个狗粮,然后有3种操作.
g i,代表第i只狗碗加1个狗粮
s i j 代表第i只狗和第j只狗的碗交换
e i 代表第i只狗吃完这个对应碗的狗粮
然后给你 k个这种命令,并且对这些操作循环做m次,求最后每个碗剩下的狗粮.
个人感想:玄学A题法,就是跟学弟讨论暴力找循环节就可以过,我就感觉可能会超时,,但是并没有超,
我们的想法是这样的,例如这一次的结果和上一次的结果 做差值,得到每个碗的增量,
每个碗的增量肯定达到一定程度上就会出现循环节,然后我们就先找到循环节的位置,
如果说循环的操作没达到循环节,那么直接操作就好了,
如果说操作达到了循环节,先把没达到循环节的增量做了,然后再做循环节,最后做循环节多余出来的次数,即可….
nnd,超级坑,这个循环节的头部出现是不知道在什么时候的,就想循环小数一样的,可能出现的在很后面.
分析:规律
代码:
题意:就是给你一n只狗,一开始每只狗的碗有0个狗粮,然后有3种操作.
g i,代表第i只狗碗加1个狗粮
s i j 代表第i只狗和第j只狗的碗交换
e i 代表第i只狗吃完这个对应碗的狗粮
然后给你 k个这种命令,并且对这些操作循环做m次,求最后每个碗剩下的狗粮.
个人感想:玄学A题法,就是跟学弟讨论暴力找循环节就可以过,我就感觉可能会超时,,但是并没有超,
我们的想法是这样的,例如这一次的结果和上一次的结果 做差值,得到每个碗的增量,
每个碗的增量肯定达到一定程度上就会出现循环节,然后我们就先找到循环节的位置,
如果说循环的操作没达到循环节,那么直接操作就好了,
如果说操作达到了循环节,先把没达到循环节的增量做了,然后再做循环节,最后做循环节多余出来的次数,即可….
nnd,超级坑,这个循环节的头部出现是不知道在什么时候的,就想循环小数一样的,可能出现的在很后面.
分析:规律
代码:
/* Author:GavinjouElephant * Title: * Number: * main meanning: * * * */ #include <iostream> using namespace std; #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <sstream> #include <cctype> #include <vector> #include <set> #include <cstdlib> #include <map> #include <queue> //#include<initializer_list> //#include <windows.h> //#include <fstream> //#include <conio.h> #define MaxN 0x7fffffff #define MinN -0x7fffffff #define lson 2*k #define rson 2*k+1 typedef long long ll; const int INF=0x3f3f3f3f; const int maxn=1e5+10; int Scan()//读入整数外挂. { int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //判断正负 flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数 res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9' ) res = res * 10 + ch - '0'; return flag ? -res : res; } void Out(int a) //输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); } ll n,m,k; char org[105][2]; int torg[105][2]; ll tmp[105]; ll temp[105]; ll top; ll xunhuyanjie[10000][105]; ll O[105]; int main() { #ifndef ONLINE_JUDGE freopen("coco.txt","r",stdin); freopen("lala.txt","w",stdout); #endif while(scanf("%lld%lld%lld",&n,&m,&k),n+m+k) { memset(tmp,0,sizeof(tmp)); memset(temp,0,sizeof(temp)); memset(O,0,sizeof(O)); for(int i=0; i<k; i++) { scanf("%s",org[i]); if(org[i][0]=='g') { scanf("%d",&torg[i][0]); } else if(org[i][0]=='s') { scanf("%d%d",&torg[i][0],&torg[i][1]); } else if(org[i][0]=='e') { scanf("%d",&torg[i][0]); } } if(m==0) { for(int i=1; i<=n; i++) { if(i==1)printf("0"); else printf(" 0"); } printf("\n"); continue; } top=0; ll L=-1,R=-1; while(1) { for(int i=1; i<=n; i++) tmp[i]=temp[i]; for(int i=0; i<k; i++) { if(org[i][0]=='g') { temp[torg[i][0]]+=1; } else if(org[i][0]=='s') { swap(temp[torg[i][0]],temp[torg[i][1]]); } else if(org[i][0]=='e') { temp[torg[i][0]]=0; } } for(int i=1; i<=n; i++) { xunhuyanjie[top][i]=(temp[i]-tmp[i]); } top++; if(top>1) { for(int s=0; s<top-1; s++) { bool flag=true; for(int i=1; i<=n; i++) { if(xunhuyanjie[s][i] !=xunhuyanjie[top-1][i]) { flag=false; break; } } if(flag) { L=s,R=top-1; break; } } if(L!=-1)break; } } L++; R++; for(int t=1; t<=min(L,m); t++) { for(int i=0; i<k; i++) { if(org[i][0]=='g') { O[torg[i][0]]+=1; } else if(org[i][0]=='s') { swap(O[torg[i][0]],O[torg[i][1]]); } else if(org[i][0]=='e') { O[torg[i][0]]=0; } } } m-=L; if(m>0) { memset(tmp,0,sizeof(tmp)); for(int i=L; i<R; i++) { for(int j=1;j<=n;j++) tmp[j]+=xunhuyanjie[i][j]; } ll top=R-L; ll now=(m/top); for(int i=1; i<=n; i++) { O[i]+=tmp[i]*now; } for(int t=0; t<m%top; t++) { for(int i=0; i<k; i++) { if(org[i][0]=='g') { O[torg[i][0]]+=1; } else if(org[i][0]=='s') { swap(O[torg[i][0]],O[torg[i][1]]); } else if(org[i][0]=='e') { O[torg[i][0]]=0; } } } } for(int i=1; i<=n; i++) { if(i==1)printf("%lld",O[i]); else printf(" %lld",O[i]); } printf("\n"); } return 0; }
相关文章推荐
- POJ 3735 Training little cats(矩阵乘法 + 稀疏矩阵优化)——2016弱校联盟十一专场10.7(12点场)
- 2016弱校联盟十一专场10.7(12点场)-D. Blocks
- 2016弱校联盟十一专场10.7(12点场)-M. Subimage Recognition
- [Contests]2016弱校联盟十一专场10.7
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing bnu 52325
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing
- POJ 3735 Training little cats(矩阵快速幂)
- POJ 3735:Training little cats 联想到矩阵相乘
- poj3757 Training little cats
- 2016弱校联盟十一专场10.2——Around the World
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- poj 3735 Training little cats (矩阵快速幂)
- poj 3735 Training little cats(构造矩阵)
- Training little cats
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- 【POJ 3735】Training little cats(万万没想到の矩快)
- poj 3735 Training little cats 矩阵快速幂+稀疏矩阵乘法优化