A P3741 honoka的键盘
和昨天的T1一样,
枚举改哪一个
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 inline int read() 8 { 9 char c=getchar();int flag=1,x=0; 10 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 11 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 12 } 13 int n; 14 char s[MAXN]; 15 int ans=0; 16 inline void pd() 17 { 18 int now=0; 19 for(int i=1;i<=n-1;i++) 20 if(s[i]=='V'&&s[i+1]=='K') 21 now++; 22 ans=max(ans,now); 23 } 24 int main() 25 { 26 n=read(); 27 scanf("%s",s+1); 28 int l=strlen(s+1); 29 pd(); 30 for(int i=1;i<=n;i++) 31 { 32 char p=s[i]; 33 if(p=='V') 34 { 35 s[i]='K'; 36 pd(); 37 s[i]='V'; 38 } 39 else 40 { 41 s[i]='V'; 42 pd(); 43 44 s[i]='K'; 45 } 46 } 47 printf("%d",ans); 48 return 0; 49 }
B P2911 [USACO08OCT]牛骨头Bovine Bones
三重循环
记录好出现的次数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 inline int read() 8 { 9 char c=getchar();int flag=1,x=0; 10 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 11 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 12 } 13 int happen[MAXN]; 14 int main() 15 { 16 int a=read(),b=read(),c=read(); 17 for(int i=1;i<=a;i++) 18 for(int j=1;j<=b;j++) 19 for(int k=1;k<=c;k++) 20 happen[i+j+k]++; 21 int ans=0; 22 int num=0; 23 for(int i=1;i<=a+b+c;i++) 24 { 25 if(happen[i]>num) 26 { 27 num=happen[i]; 28 ans=i; 29 } 30 } 31 printf("%d",ans); 32 return 0; 33 }
C P1765 手机_NOI导刊2010普及(10)
打个表,预处理出每个字母需要几次
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 inline int read() 8 { 9 char c=getchar();int flag=1,x=0; 10 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 11 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 12 } 13 int a[501]; 14 int main() 15 { 16 int now=1; 17 for(int i='a';i<='o';i++) 18 { 19 a[i]=now++; 20 if(now==4) now=1; 21 } 22 a['p']=1; a['q']=2; a['r']=3; a['s']=4; 23 a['t']=1; a['u']=2; a['v']=3; 24 a['w']=1; a['x']=2; a['y']=3; a['z']=4; 25 a[' ']=1; 26 char c; 27 int ans=0; 28 while(scanf("%c",&c)==1) 29 ans+=a[c]; 30 printf("%d",ans); 31 return 0; 32 }
D P1482 Cantor表(升级版)
用最大公约数进行约分
注意n,m不要搞反了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 inline int read() 8 { 9 char c=getchar();int flag=1,x=0; 10 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 11 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 12 } 13 int a,b,c,d; 14 int gcd(int a,int b) 15 { 16 return b==0?a:gcd(b,a%b); 17 } 18 int main() 19 { 20 scanf("%d/%d",&a,&b); 21 scanf("%d/%d",&c,&d); 22 int p=gcd(a,b); 23 a/=p;b/=p; 24 p=gcd(c,d); 25 c/=p;d/=p; 26 p=gcd(c,b); 27 c/=p;b/=p; 28 p=gcd(a,d); 29 a/=p;d/=p; 30 printf("%d %d",b*d,a*c); 31 return 0; 32 }
E P2651 添加括号III
最难的一道题
很显然的一点是
第一个一定是分子
第二个一定是分母
分子越大越好
那么就看一下a1*a3*a4*……an能不能整除a2就好
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #define LL long long 6 using namespace std; 7 const LL MAXN=1e7+10; 8 inline LL read() 9 { 10 char c=getchar();LL flag=1,x=0; 11 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 12 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 13 } 14 LL T; 15 LL a[MAXN]; 16 LL gcd(LL a,LL b) 17 { 18 return b==0?a:gcd(b,a%b); 19 } 20 int main() 21 { 22 T=read(); 23 while(T--) 24 { 25 a[2]=1; 26 LL n=read(); 27 for(LL i=1;i<=n;i++) a[i]=read(); 28 int mu=a[2]; 29 mu/=gcd(a[1],mu); 30 for(LL i=3;i<=n;i++) 31 mu/=gcd(mu,a[i]); 32 if(mu==1) printf("Yes "); 33 else printf("No "); 34 } 35 return 0; 36 }
F P2369 EXCEEDED WARNING A
很水的一道排序题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e6+10; 7 inline int read() 8 { 9 char c=getchar();int flag=1,x=0; 10 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 11 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 12 } 13 int n,m; 14 int a[MAXN]; 15 int main() 16 { 17 n=read();m=read(); 18 for(int i=1;i<=n;i++) a[i]=read(); 19 sort(a+1,a+n+1); 20 for(int i=1;i<=m;i++) 21 printf("%d ",a[i]); 22 return 0; 23 }
G P2562 [AHOI2002]Kitty猫基因编码
用string记录状态,递归计算
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<map> 6 #include<iostream> 7 using namespace std; 8 const int MAXN=1001; 9 inline int read() 10 { 11 char c=getchar();int flag=1,x=0; 12 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 13 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 14 } 15 string ans; 16 char a[MAXN]; 17 string A="A"; 18 string B="B"; 19 string C="C"; 20 void dfs(int l,int r) 21 { 22 int flag1=1,flag0=1; 23 for(int i=l;i<=r;i++) 24 { 25 if(a[i]=='0') flag1=0; 26 if(a[i]=='1') flag0=0; 27 } 28 if(flag0) ans+=A; 29 else if(flag1) ans+=B; 30 else 31 { 32 ans+=C; 33 int mid=l+r>>1; 34 dfs(l,mid);dfs(mid+1,r); 35 } 36 } 37 int main() 38 { 39 scanf("%s",a+1); 40 dfs(1,strlen(a+1)); 41 cout<<ans; 42 return 0; 43 }
H P2548 [AHOI2004]智能探险车
开一个二维string
直接用string判重
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<map> 6 #include<iostream> 7 using namespace std; 8 const int MAXN=1001; 9 inline int read() 10 { 11 char c=getchar();int flag=1,x=0; 12 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 13 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 14 } 15 string a[MAXN][MAXN]; 16 int flag[MAXN]; 17 int main() 18 { 19 int n=read(),m=read(); 20 for(int i=1;i<=m;i++) 21 for(int j=1;j<=n;j++) 22 cin>>a[i][j]; 23 for(int i=2;i<=m;i++) 24 for(int j=1;j<=n;j++) 25 if(a[i][j]!=a[i-1][j]) 26 flag[j]=1; 27 for(int i=1;i<=n;i++) 28 { 29 if(flag[i]==1) printf("* "); 30 else cout<<a[m][i]<<" "; 31 } 32 return 0; 33 }
I P1539 [TJOI2011]01矩阵
这道题好像从10.5改了题目之后就没人A过
自己瞎搞了一个dp,水到10分23333
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<map> 6 #include<iostream> 7 using namespace std; 8 const int MAXN=1001; 9 inline int read() 10 { 11 char c=getchar();int flag=1,x=0; 12 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 13 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 14 } 15 int dp[MAXN][MAXN][3]; 16 int n,m; 17 char s[MAXN]; 18 int main() 19 { 20 n=read();m=read(); 21 for(int i=1;i<=n;i++) 22 { 23 scanf("%s",s); 24 for(int j=1;j<=m;j++) 25 { 26 if(s[j]=='1') dp[i][j][1]=1; 27 if(s[j]=='0') dp[i][j][0]=1; 28 } 29 } 30 for(int i=1;i<=n;i++) 31 { 32 for(int j=1;j<=m;j++) 33 { 34 if(dp[i][j][1]!=1&&dp[i][j]!=0) 35 { 36 dp[i][j][1]+=dp[i-1][j][0]; 37 dp[i][j][1]+=dp[i-1][j][1]; 38 dp[i][j][1]+=dp[i+1][j][0]; 39 dp[i][j][1]+=dp[i+1][j][1]; 40 dp[i][j][1]+=dp[i][j-1][0]; 41 dp[i][j][1]+=dp[i][j-1][1]; 42 dp[i][j][1]+=dp[i][j+1][0]; 43 dp[i][j][1]+=dp[i][j+1][1]; 44 45 dp[i][j][0]+=dp[i-1][j][1]; 46 dp[i][j][0]+=dp[i+1][j][1]; 47 dp[i][j][0]+=dp[i][j-1][1]; 48 dp[i][j][0]+=dp[i][j+1][1]; 49 } 50 51 } 52 } 53 printf("%d",max(dp[n][m][0],dp[n][m][1])); 54 return 0; 55 }
J P3879 [TJOI2010]阅读理解
map的裸题
可以写map<string,vector>
但是我不会写,就自己定义了个结构体
对于每一个字符串的读入
不要忘记判断该序号是否已经出现过
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<map> 6 #include<iostream> 7 using namespace std; 8 const int MAXN=1e6+10; 9 inline int read() 10 { 11 char c=getchar();int flag=1,x=0; 12 while(c<'0'||c>'9') {if(c=='-') flag=-1;c=getchar();} 13 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*flag; 14 } 15 int n,m; 16 struct node 17 { 18 int happen[438]; 19 int time; 20 }; 21 map<string,node>mp; 22 inline void pd(string a,int pos) 23 { 24 if(mp[a].happen[mp[a].time]==pos) return ;//注意序号不能重复 25 mp[a].happen[++mp[a].time]=pos; 26 } 27 int main() 28 { 29 n=read(); 30 for(int i=1;i<=n;i++) 31 { 32 int num=read(); 33 string a; 34 for(int j=1;j<=num;j++) 35 cin>>a,pd(a,i); 36 } 37 m=read(); 38 for(int i=1;i<=m;i++) 39 { 40 string a;cin>>a; 41 for(int i=1;i<=mp[a].time;i++) 42 printf("%d ",mp[a].happen[i]); 43 printf(" "); 44 } 45 return 0; 46 }