2017年ACM-ICPC青岛站(现场赛)E题 伯利亚定理
来源:互联网 发布:轻松的工作 知乎 编辑:程序博客网 时间:2024/04/28 23:20
#include<bits/stdc++.h>using namespace std;string s,ans[2005];int cnt,sum[35];map<string,int> flag;void dfs(string s){ if(flag[s]) return; ans[cnt++]=s; flag[s]=1; string tmp; tmp=s; swap(tmp[0],tmp[15]); swap(tmp[3],tmp[12]); swap(tmp[6],tmp[9]); swap(tmp[18],tmp[21]); swap(tmp[24],tmp[26]); dfs(tmp); tmp=s; swap(tmp[6],tmp[17]); swap(tmp[7],tmp[16]); swap(tmp[8],tmp[15]); swap(tmp[26],tmp[29]); swap(tmp[18],tmp[20]); dfs(tmp); tmp=s; swap(tmp[2],tmp[17]); swap(tmp[5],tmp[14]); swap(tmp[8],tmp[11]); swap(tmp[23],tmp[20]); swap(tmp[27],tmp[29]); dfs(tmp); tmp=s; swap(tmp[0],tmp[11]); swap(tmp[1],tmp[10]); swap(tmp[2],tmp[9]); swap(tmp[24],tmp[27]); swap(tmp[21],tmp[23]); dfs(tmp); tmp=s; swap(tmp[0],tmp[15]); swap(tmp[1],tmp[16]); swap(tmp[2],tmp[17]); swap(tmp[3],tmp[12]); swap(tmp[4],tmp[13]); swap(tmp[5],tmp[14]); swap(tmp[6],tmp[9]); swap(tmp[7],tmp[10]); swap(tmp[8],tmp[11]); swap(tmp[21],tmp[18]); swap(tmp[22],tmp[19]); swap(tmp[23],tmp[20]); swap(tmp[24],tmp[26]); swap(tmp[27],tmp[29]); dfs(tmp); tmp=s; swap(tmp[0],tmp[11]); swap(tmp[3],tmp[14]); swap(tmp[6],tmp[17]); swap(tmp[1],tmp[10]); swap(tmp[4],tmp[13]); swap(tmp[7],tmp[16]); swap(tmp[2],tmp[9]); swap(tmp[5],tmp[12]); swap(tmp[8],tmp[15]); swap(tmp[21],tmp[23]); swap(tmp[18],tmp[20]); swap(tmp[24],tmp[27]); swap(tmp[25],tmp[28]); swap(tmp[26],tmp[29]); dfs(tmp); tmp[4]=s[4]; tmp[13]=s[13]; tmp[0]=s[2]; tmp[1]=s[5]; tmp[2]=s[8]; tmp[5]=s[7]; tmp[8]=s[6]; tmp[7]=s[3]; tmp[6]=s[0]; tmp[3]=s[1]; tmp[9]=s[11]; tmp[10]=s[14]; tmp[11]=s[17]; tmp[14]=s[16]; tmp[17]=s[15]; tmp[16]=s[12]; tmp[15]=s[9]; tmp[12]=s[10]; tmp[21]=s[27]; tmp[22]=s[28]; tmp[23]=s[29]; tmp[27]=s[20]; tmp[28]=s[19]; tmp[29]=s[18]; tmp[20]=s[26]; tmp[19]=s[25]; tmp[18]=s[24]; tmp[26]=s[21]; tmp[25]=s[22]; tmp[24]=s[23]; dfs(tmp); tmp[4]=s[4]; tmp[13]=s[13]; tmp[0]=s[6]; tmp[1]=s[3]; tmp[2]=s[0]; tmp[5]=s[1]; tmp[8]=s[2]; tmp[7]=s[5]; tmp[6]=s[8]; tmp[3]=s[7]; tmp[9]=s[15]; tmp[10]=s[12]; tmp[11]=s[9]; tmp[14]=s[10]; tmp[17]=s[11]; tmp[16]=s[14]; tmp[15]=s[17]; tmp[12]=s[16]; tmp[21]=s[26]; tmp[22]=s[25]; tmp[23]=s[24]; tmp[27]=s[21]; tmp[28]=s[22]; tmp[29]=s[23]; tmp[20]=s[27]; tmp[19]=s[28]; tmp[18]=s[29]; tmp[26]=s[20]; tmp[25]=s[19]; tmp[24]=s[18]; dfs(tmp);}void solve(string s){ bool vis[35]={false},flag=false; int cnt=0; for(int i=0;i<s.length();i++) { if(vis[i]) continue; else vis[i]=true; int j=i; while(s[j]!=i+65) { j=s[j]-65; vis[j]=true; } cnt++; } sum[cnt]++;}void init(){ for(int i=0;i<30;i++) s+=i+65; dfs(s); for(int i=0;i<cnt;i++) solve(ans[i]);}typedef long long ll;ll n,p;ll quick_mod(ll n,ll m,ll mod){ ll res=1; while(m) { if(m&1) res=res*n%mod; n=n*n%mod; m>>=1; } return res;}void cal(ll n,ll p){ ll res=0; for(int i=0;i<=30;i++) if(sum[i]) res=(res+sum[i]%(p*cnt)*quick_mod(n,i,p*cnt)%(p*cnt))%(p*cnt); printf("%lld\n",res/cnt);}int main(){ init(); int t; scanf("%d",&t); while(t--&&scanf("%lld%lld",&n,&p)!=EOF) cal(n,p); return 0;}/*0 1 23 4 56 7 89 10 1112 13 1415 16 1721 22 2318 19 2024 2725 2826 29*/
阅读全文
0 0
- 2017年ACM-ICPC青岛站(现场赛)E题 伯利亚定理
- 2017年第42届ACM-ICPC亚洲区域赛青岛赛区(现场赛)
- 2016 acm/icpc 青岛站现场赛 3道题
- 2017年ACM/ICPC青岛站感想
- 2017ACM-ICPC亚洲区域赛(青岛站)
- 2017 ACM-ICPC 青岛站
- 2017 acm-icpc 青岛站 E题 FloppyCube (Polay计数 dfs找循环节)
- 2016 ACM-ICPC 亚洲区(青岛赛区)现场赛
- 2017 ACM-ICPC 青岛站 总结
- 2017 ACM 区域赛青岛站(现场赛) K Our Journey of Xian Ends
- ACM创新实验室代表队成功闯入ICPC ACM青岛区域赛现场赛
- ACM ICPC 长春现场赛E Conquer a New Region
- ACM/ICPC青岛站总结
- HDU5074 ACM-ICPC亚洲区域赛鞍山赛区现场赛E题 Hatsune Miku 二维DP
- 2017ICPC/ACM亚洲赛区西安站现场赛 总结
- 2014ACM/ICPC亚洲区鞍山赛区现场赛E(hdu 5074)
- 2016 acm/icpc 大连站现场赛(7道题)
- ACM-ICPC亚洲区域赛青岛站总结
- 文件的播发,python,UDP协议
- JavaScript 鼠标事件改变背景图片
- Linux /etc/profile文件详解
- Java 生成 UUID
- linux 端口开放
- 2017年ACM-ICPC青岛站(现场赛)E题 伯利亚定理
- windows下Apache2.4和Tomcat7动静分离配置
- 自己填充int数组,生成bitmap,显示一张纯色图。
- 远程访问共享文件夹
- android安卓入门技能篇
- SAP S/4 Hana On-premise Edition 1511做了哪些简化
- 笔记30 | 数据存储之SQLite的介绍及使用
- 成功只差一步之遥
- 安装词云wordcloud报错:Microsoft Visual C++ 14.0 is required.