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 思路:
二维前缀和
#include <iostream>
#include <algorithm>
#include <cstdio>
int t,m,n,x,y,a[][],dp[][];
using namespace std;
int main()
{ cin>>t;
while(t--)
{
cin>>m>>n>>x>>y;
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
{
cin>>a[i][j];
}
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
{
dp[i][j]=a[i][j]+dp[i][j-]+dp[i-][j]-dp[i-][j-];
}
long long ans=;
for(int i=;i<=m-x;i++)
for(int j=;j<=n;j++)
{
long long ii=i+x-,jj=j+y-;
long long t=dp[ii][jj]-dp[i-][jj]-dp[ii][j-]+dp[i-][j-];
ans=max(ans,t);
}
cout<<ans<<endl;
}
}
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".
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string s,t;
cin>>n;
while(n--)
{
cin>>s>>t;
int ls=s.size();
int w=;
for(int i=;i<ls;i++)
{
for(int j=;j<ls;j++)
if(s[i]==t[j])
{
w=;
break;
}
}
if(w==)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
} }
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 一维前缀和
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,a,b;
while(scanf("%d",&n)!=EOF)
{
if(n==) return ;
int m[]={};
int t=n;int s=;
while(n--)
{
cin>>a>>b;
m[a]++;m[b+]--; }
for(int i=;i<=t;i++)
{
s+=m[i];
cout<<s;
printf("%c",i==t?'\n':' ');
}
} }
SDNU_ACM_ICPC_2020_Winter_Practice_2nd的更多相关文章
随机推荐
- 【Python】字符串操作符
- elementui el-table根据分页显示表格序号
每页显示的序号都是一样的: <el-table :data="tableData" highlight-current-row @current-change="h ...
- sql语句代码规范
19年年底的时候领导一直强调代码规范化以前写代码的时候很随意后来越来越看自己写的代码难受逐渐的也像规范化走去,今天又学了一招记录分享一下 这张图就是以前写代码的时候正常情况很是杂乱无章 这张就是规范话 ...
- echart如何去掉X 、Y轴的网格线
1.如何去掉X.Y轴的网格线,关键是splitLine{show:false} xAxis:[{ type:'value', splitNumber:2, scale:true, splitLine: ...
- 【C语言】利用二维数组输出成绩
目的:用二维数组输出下面成绩 希望你可以成为第五名童鞋! 代码: #include<stdio.h> int main() { /* 创建一个带有 4行 5 列的数组 */ ][] = { ...
- HTML学习(17)URL
HTML 统一资源定位器(Uniform Resource Locators) URL - 统一资源定位器 Web浏览器通过URL从Web服务器请求页面. scheme://host.domain:p ...
- [HDU5382]GCD?LCM!
Description HDU5382 会吗?不会! 设\(F(n)=\sum\limits_{i = 1}^{n}\sum\limits_{j=1}^{n}[lcm(i,j)+gcd(i,j)\ge ...
- iview渲染函数
<Table border :columns="discountColumns" :data="discountData.rows"></Ta ...
- Qt入门-表格类QTableWidget
原文 :http://blog.csdn.net/xgbing/article/details/7774737 表格是GUI中常用的控件,在Qt中,常用的表格类是QTableWidget. 示例: Q ...
- bugku 矛盾 30
首先打开网址链接会发现一串代码 然后进行分析代码的意思首先是一个函数查一下这个函数 然后会发现现代码第一句写的是输入数字,然后会发现第二行有一个感叹号意思是输入的如果不是数字则回复数字 如果输入数字则 ...