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的更多相关文章
随机推荐
- echart--自己写的例子
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- python property(不动产)方法
class Test(object): @property def test(self): return 100 @test.setter def test(self): return "修 ...
- 剑指offer 面试题. 按之字形顺序打印二叉树
题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 方法1: 正常层次遍历,利用普通队列.逢 ...
- php 基础系列之 php快速入门
·插补操作 将简单变量写入一个由双引号引用的字符串中,就叫插补操作.例如: $test = 'xx'; echo "你好:$test"; 注意:插补操作只是双引号引用字符串的特性. ...
- Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3
环境 Deepin Linux 15.11 Django 2.2 pymysql0.9.3 原因 因为用pymysql替换了默认的mysqlclient,Django官方推荐的数据库API drive ...
- 转载一篇棒棒的AWK教程
处理文件经常要用到awk,老是找同事帮忙,次数多了难免被吐槽orz,其实之前也有找过awk的教程,表示一直看不太懂 最近翻到了这篇教程,表示笔者真的太棒了,反正我是看一遍就懂了哈哈 剩下的只是熟悉度的 ...
- Django_视图
1. 视图 1.1 返回json数据 2. url配置 url组成 3. 获取 url参数 别名 4. url反向解析 接收参数 reverse 5. 视图总结 5.1 自定义错误页面 6. Http ...
- Dockerfile书写介绍及构建ssh镜像、tomcat镜像、nginx镜像
=================================================================================================== ...
- MySQL-THINKPHP 商城系统一 商品模块的设计
在此之前,先了解下关于SPU及SKU的知识 SPU是商品信息聚合的最小单位,是一组可复用.易检索的标准化信息的集合,该集合描述了一个产品的特性.通俗点讲,属性值.特性相同的商品就可以称为一个SPU. ...
- Vue - 解决路由过渡动画抖动问题
前言 Vue-Router 作为 Vue 的核心模块,它为我们提供了基于组件的路由配置.路由参数等功能,让单页面应用变得更易于管理.良好的路由管理尤为重要,比如路由拦截.路由懒加载.路由权限等都在开发 ...