SDNU_ACM_ICPC_2020_Winter_Practice_2nd
A - 【The__Flash】的矩阵
Input输入数据的第一行为一个正整数T,表示有T组测试数据。每一组测试数据的第一行为四个正整数m,n,x,y(0<m,n<1000 AND 0<x<=m AND 0<y<=n),表示给定的矩形有m行n列。接下来这个矩阵,有m行,每行有n个不大于1000的正整数。Output对于每组数据,输出一个整数,表示子矩阵的最大和。
Sample Input
1 4 5 2 2 3 361 649 676 588 992 762 156 993 169 662 34 638 89 543 525 165 254 809 280
Sample Output
2474
思路:
二维前缀和
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 int t,m,n,x,y,a[1005][1005],dp[1005][1005]; 5 using namespace std; 6 int main() 7 { 8 9 cin>>t; 10 while(t--) 11 { 12 cin>>m>>n>>x>>y; 13 for(int i=1;i<=m;i++) 14 for(int j=1;j<=n;j++) 15 { 16 cin>>a[i][j]; 17 } 18 for(int i=1;i<=m;i++) 19 for(int j=1;j<=n;j++) 20 { 21 dp[i][j]=a[i][j]+dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]; 22 } 23 long long ans=0; 24 for(int i=1;i<=m-x;i++) 25 for(int j=1;j<=n;j++) 26 { 27 long long ii=i+x-1,jj=j+y-1; 28 long long t=dp[ii][jj]-dp[i-1][jj]-dp[ii][j-1]+dp[i-1][j-1]; 29 ans=max(ans,t); 30 } 31 cout<<ans<<endl; 32 } 33 }
G - 【The__Flash】的水题
You are given two strings of equal length ss and tt consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.
For example, if ss is "acbc" you can get the following strings in one operation:
- "aabc" (if you perform s2=s1s2=s1 );
- "ccbc" (if you perform s1=s2s1=s2 );
- "accc" (if you perform s3=s2s3=s2 or s3=s4s3=s4 );
- "abbc" (if you perform s2=s3s2=s3 );
- "acbb" (if you perform s4=s3s4=s3 );
Note that you can also apply this operation to the string tt .
Please determine whether it is possible to transform ss into tt , applying the operation above any number of times.
Note that you have to answer qq independent queries.
Input
The first line contains one integer qq (1≤q≤1001≤q≤100 ) — the number of queries. Each query is represented by two consecutive lines.
The first line of each query contains the string ss (1≤|s|≤1001≤|s|≤100 ) consisting of lowercase Latin letters.
The second line of each query contains the string tt (1≤|t|≤1001≤|t|≤100 , |t|=|s||t|=|s| ) consisting of lowercase Latin letters.
Output
For each query, print "YES" if it is possible to make ss equal to tt , and "NO" otherwise.
You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive answer).
Example
3 xabb aabx technocup technocup a z
YES YES NO
Note
In the first query, you can perform two operations s1=s2s1=s2 (after it ss turns into "aabb") and t4=t3t4=t3 (after it tt turns into "aabb").
In the second query, the strings are equal initially, so the answer is "YES".
In the third query, you can not make strings ss and tt equal. Therefore, the answer is "NO".
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 { 6 int n; 7 string s,t; 8 cin>>n; 9 while(n--) 10 { 11 cin>>s>>t; 12 int ls=s.size(); 13 int w=0; 14 for(int i=0;i<ls;i++) 15 { 16 for(int j=0;j<ls;j++) 17 if(s[i]==t[j]) 18 { 19 w=1; 20 break; 21 } 22 } 23 if(w==1) 24 cout<<"YES"<<endl; 25 else 26 cout<<"NO"<<endl; 27 } 28 29 }
Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。Output每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。Sample Input
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
Sample Output
1 1 1 3 2 1
一维前缀和
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main() 5 { 6 int n,a,b; 7 while(scanf("%d",&n)!=EOF) 8 { 9 if(n==0) return 0; 10 int m[100005]={0}; 11 int t=n;int s=0; 12 while(n--) 13 { 14 cin>>a>>b; 15 m[a]++;m[b+1]--; 16 17 } 18 for(int i=1;i<=t;i++) 19 { 20 s+=m[i]; 21 cout<<s; 22 printf("%c",i==t?'\n':' '); 23 } 24 } 25 26 27 }