2022/6/25随笔
//P4924 [1007]魔法少女小Scarlet
https://www.luogu.com.cn/problem/P4924
//不要把空间开太大,会被oj卡,空间要求上加10就可以了
//矩阵旋转是以中心为支点的旋转,就是几何旋转,可以理解为魔方面的旋转
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int maxn=510; 5 int a[maxn][maxn]; 6 int tmp[maxn][maxn]; 7 int n,m; 8 void gz(int x,int y,int r) 9 { 10 int x1=x-r; 11 int y1=y-r; 12 for(int i=x-r;i<=x+r;i++) 13 { 14 for(int j=y-r;j<=y+r;j++) 15 { 16 tmp[i][j]=a[i][j]; 17 } 18 } 19 } 20 void shun(int x,int y,int r) 21 { 22 int x1=x-r,y1=y-r; 23 for(int i=y+r;i>=y-r;i--) 24 { 25 for(int j=x-r;j<=x+r;j++) 26 { 27 a[j][i]=tmp[x1][y1]; 28 y1++; 29 } 30 x1++; 31 y1=y-r; 32 } 33 } 34 void ni(int x,int y,int r) 35 { 36 int x1=x-r,y1=y-r; 37 for(int i=y-r;i<=y+r;i++) 38 { 39 for(int j=x+r;j>=x-r;j--) 40 { 41 a[j][i]=tmp[x1][y1]; 42 y1++; 43 } 44 x1++; 45 y1=y-r; 46 } 47 } 48 int main() 49 { 50 cin>>n>>m; 51 int k=1; 52 for(int i=1;i<=n;i++) 53 { 54 for(int j=1;j<=n;j++) 55 { 56 a[i][j]=k; 57 k++; 58 } 59 } 60 int x,y,r,z; 61 for(int i=1;i<=m;i++) 62 { 63 fill(tmp[0],tmp[0]+maxn*maxn,0); 64 cin>>x>>y>>r>>z; 65 gz(x,y,r); 66 if(z==0) 67 shun(x,y,r); 68 else if(z==1) 69 ni(x,y,r); 70 } 71 for(int i=1;i<=n;i++) 72 { 73 for(int j=1;j<=n;j++) 74 { 75 cout<<a[i][j]<<" "; 76 } 77 cout<<endl; 78 } 79 return 0; 80 }

//P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布
https://www.luogu.com.cn/problem/P1328
//0剪刀赢蜥蜴人、布;输斯波克、石头
//1石头赢蜥蜴人、剪刀;输斯波克、布
//2布赢斯波克、石头;输蜥蜴人、剪刀
//3蜥蜴人赢布、斯波克;斯波克输石头、剪刀
//4斯波克赢剪刀、石头;输蜥蜴人 、布
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int maxn=210; 5 int a[maxn],b[maxn]; 6 int n,x,y; 7 int w=0,l=0; 8 int main() 9 { 10 cin>>n>>x>>y; 11 for(int i=0;i<x;i++) 12 { 13 cin>>a[i]; 14 } 15 for(int i=0;i<y;i++) 16 { 17 cin>>b[i]; 18 } 19 for(int i=0;i<n;i++) 20 { 21 int j=a[i%x]; 22 int k=b[i%y]; 23 if(j==0) 24 { 25 if(k==3||k==2) 26 w++; 27 else if(k==4||k==1) 28 l++; 29 } 30 else if(j==1) 31 { 32 if(k==3||k==0) 33 w++; 34 else if(k==4||k==2) 35 l++; 36 } 37 else if(j==2) 38 { 39 if(k==4||k==1) 40 w++; 41 else if(k==3||k==0) 42 l++; 43 } 44 else if(j==3) 45 { 46 if(k==2||k==4) 47 w++; 48 else if(k==0||k==1) 49 l++; 50 } 51 else if(j==4) 52 { 53 if(k==0||k==1) 54 w++; 55 else if(k==2||k==3) 56 l++; 57 } 58 } 59 cout<<w<<" "<<l<<endl; 60 return 0; 61 }

//P1518 [USACO2.4]两只塔姆沃斯牛 The Tamworth Two
https://www.luogu.com.cn/problem/P1518
//做模拟题可以先列出思维导图,一步一步写代码
//逻辑清晰方便编写和修改
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 using namespace std; 5 int cnt=0; 6 char a[15][15]; 7 int x1,x2,y1,y2; 8 int xx[4]={-1,0,1,0}; 9 int yy[4]={0,1,0,-1}; 10 int main() 11 { 12 int k1=0,k2=0; 13 for(int i=1;i<=10;i++) 14 { 15 for(int j=1;j<=10;j++) 16 { 17 cin>>a[i][j]; 18 if(a[i][j]=='C') 19 { 20 x1=i; 21 y1=j; 22 } 23 if(a[i][j]=='F') 24 { 25 x2=i; 26 y2=j; 27 } 28 } 29 } 30 while(1) 31 { 32 if(x1==x2&&y1==y2) 33 { 34 cout<<cnt<<endl; 35 return 0; 36 } 37 if(a[x1+xx[k1]][y1+yy[k1]]=='*'||x1+xx[k1]<1||x1+xx[k1]>10||y1+yy[k1]<1||y1+yy[k1]>10) 38 { 39 k1=(k1+1)%4; 40 } 41 else 42 { 43 x1=x1+xx[k1]; 44 y1=y1+yy[k1]; 45 } 46 if(a[x2+xx[k2]][y2+yy[k2]]=='*'||x2+xx[k2]<1||x2+xx[k2]>10||y2+yy[k2]<1||y2+yy[k2]>10) 47 { 48 k2=(k2+1)%4; 49 } 50 else 51 { 52 x2=x2+xx[k2]; 53 y2=y2+yy[k2]; 54 } 55 cnt++; 56 if(cnt>=100000) 57 { 58 cout<<"0"<<endl; 59 return 0; 60 } 61 } 62 return 0; 63 }

//P1098 [NOIP2007 提高组] 字符串的展开
P1098 [NOIP2007 提高组] 字符串的展开 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
1 #include<iostream> 2 #include<algorithm> 3 #include<stdio.h> 4 using namespace std; 5 const int maxn=205; 6 int n,m,q; 7 string a,b; 8 int main() 9 { 10 cin>>n>>m>>q; 11 cin>>a; 12 for(int i=0;i<a.size();i++) 13 { 14 b.erase(0,b.size()); 15 if(a[i]!='-') 16 { 17 cout<<a[i]; 18 } 19 else 20 { 21 char c1=a[i-1],c2=a[i+1]; 22 int j=0; 23 if(c1<c2&&((c1>='0'&&c1<='9'&&c2>='0'&&c2<='9')||c1>='a'&&c1<='z'&&c2>='a'&&c2<='z')) 24 { 25 for(char i=c1+1;i<=c2-1;i++) 26 { 27 b=b+i; 28 } 29 if(q==1) 30 { 31 for(int i=0;i<b.size();i++) 32 { 33 for(int w=1;w<=m;w++) 34 { 35 if(b[i]>='a'&&b[i]<='z') 36 { 37 if(n==1) 38 cout<<b[i]; 39 else if(n==2) 40 printf("%c",b[i]-32); 41 else if(n==3) 42 cout<<"*"; 43 } 44 else 45 { 46 if(n==3) 47 cout<<"*"; 48 else 49 cout<<b[i]; 50 } 51 } 52 } 53 } 54 else if(q==2) 55 { 56 for(int i=b.size()-1;i>=0;i--) 57 { 58 for(int w=1;w<=m;w++) 59 { 60 if(b[i]>='a'&&b[i]<='z') 61 { 62 if(n==1) 63 cout<<b[i]; 64 else if(n==2) 65 printf("%c",b[i]-32); 66 else if(n==3) 67 cout<<"*"; 68 } 69 else 70 { 71 if(n==3) 72 cout<<"*"; 73 else 74 cout<<b[i]; 75 } 76 } 77 } 78 } 79 } 80 else 81 cout<<a[i]; 82 } 83 } 84 return 0; 85 }

//P1067 [NOIP2009 普及组] 多项式输出
https://www.luogu.com.cn/problem/P1067
//特判太多了,模拟题一定多读几遍题,把所有情况都考虑到
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 int n; 5 int a[105]; 6 int main() 7 { 8 cin>>n; 9 for(int i=0;i<=n;i++) 10 { 11 cin>>a[i]; 12 } 13 int j; 14 for(j=0;j<=n;j++) 15 { 16 if(a[j]!=0) 17 { 18 if(a[j]>1) 19 cout<<a[j]<<"x"<<"^"<<n-j; 20 else if(a[j]<-1) 21 cout<<a[j]<<"x"<<"^"<<n-j; 22 else 23 { 24 if(a[j]>0) 25 cout<<"x"<<"^"<<n-j; 26 else 27 cout<<"-x"<<"^"<<n-j; 28 } 29 break; 30 } 31 } 32 for(int i=j+1;i<=n;i++) 33 { 34 if(a[i]!=0) 35 { 36 if((n-i)>1) 37 { 38 if(a[i]>1) 39 cout<<"+"<<a[i]<<"x"<<"^"<<n-i; 40 else if(a[i]<-1) 41 cout<<a[i]<<"x"<<"^"<<n-i; 42 else 43 { 44 if(a[i]>0) 45 cout<<"+x"<<"^"<<n-i; 46 else 47 cout<<"-x"<<"^"<<n-i; 48 } 49 } 50 else 51 { 52 if((n-i)==1) 53 { 54 if(a[i]>1) 55 cout<<"+"<<a[i]<<"x"; 56 else if(a[i]<-1) 57 cout<<a[i]<<"x"; 58 else 59 { 60 if(a[i]>0) 61 cout<<"+x"; 62 else 63 cout<<"-x"; 64 } 65 } 66 else if(a[i]>0) 67 cout<<"+"<<a[i]; 68 else 69 cout<<a[i]; 70 } 71 } 72 } 73 return 0; 74 }

//P1591 阶乘数码
https://www.luogu.com.cn/problem/P1591
#include<iostream> #include<algorithm> #include<cstring> using namespace std; int n,p,q; int a[10000005]; int cnt=0; int main() { cin>>n; while(n--) { memset(a,0,sizeof(a)); cnt=0; cin>>p>>q; a[0]=1; a[1]=1; for(int i=2;i<=p;i++) { for(int j=1;j<=a[0];j++) { a[j]=a[j]*i; } for(int j=1;j<=a[0];j++) { if(a[j]>9) { a[j+1]=a[j+1]+a[j]/10; a[j]=a[j]%10; } } while(a[a[0]+1])//解决进位问题的新方法,判断存储位+1是否为0,不为0则进位 //使用while:若为128,进一次为8,12,还要再进一次为:8 2 1 { a[a[0]+2]=a[a[0]+2]+a[a[0]+1]/10; a[a[0]+1]=a[a[0]+1]%10; a[0]++; } } for(int i=1;i<=a[0];i++) { if(a[i]==q) cnt++; } cout<<cnt<<endl; } return 0; }


浙公网安备 33010602011771号