比赛链接:click here
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
intellect
tell
1
google
apple
0
sirisiri
sir
2
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
思路:模拟就可以,找到子串的个数就可以
代码:
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; char s[maxn],t[maxn]; int main() { scanf("%s%s",s,t); int res=0; for(int i=0; i+m<=n; ++i) { bool flag=true; for(int j=0; j<m; ++j) if(s[i+j]!=t[j])flag=false; if(flag) { s[i+m-1]='#'; res++; } } printf("%d ",res); return 0; }
代码:
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn =1e5+10; int a[505][505]; int main() { int n,k; scanf("%d%d",&n,&k); int cnt=n*n; for(int i=1; i<=n; i++) { for(int j=n; j>=k; j--) { a[i][j]=cnt--; } } for(int i=1; i<=n; i++) for(int j=k-1; j>=1; j--) a[i][j]=cnt--; int tot=0; for(int i=1; i<=n; i++) tot+=a[i][k]; printf("%d ",tot); for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) printf("%s%d",(j>1 ?" " :""),a[i][j]); printf(" "); } return 0; }