【无标题】

Codeforces Round #827 (Div. 4)(A-F,G明天再补)

大概是开学后的第一次打div4了,打了5题,要不是万恶的俄罗斯时间和粗心wa两发,应该能绿名的qwq(差6分就)。

A

**题意:**给你三个数,问你其他两个数的和是不是另一个数。直接暴力就好了。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N];


int main()
{
	int t ;
	cin>>t;
	while(t--)
	{
		int x,y,z;
		cin>>x>>y>>z;
		if(x+y==z||x+z==y||y+z==x)
		{
			cout<<"YES\n";
		}
		else cout<<"NO\n";
	}
	return 0;
}

B

**题意:**给你n个数,问你这n个数能不能通过排序形成严格单调递增的序列。
直接sort一遍就可以,然后判断有没有相同的。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N];


int main()
{
	int t ;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i =1;i<=n;i++)cin>>s[i];
        sort(s+1,s+1+n);
        int p=0;
        for(int i =1;i<=n;i++)
        {
            if(s[i]==s[i+1]&&i+1<=n)
            p=1;
        }
        if(p)cout<<"NO\n";
        else cout<<"YES\n";
    }
	return 0;
}

C

题意:给你一个8*8 的网格有些水平行会被涂成红色,水平列会被涂成蓝色,先涂的会被后涂的覆盖,比如一个点被先涂成了红色,之后这个点也被涂成了蓝色,那么这个红色就会被覆盖成蓝色。

**思路:**直接暴力即可,每个点如果不是 ’ . ’ ,那就进行一次判断:
如果是蓝色,就判断这个点所在列是不是全为蓝色:
如果是红色,就判断这个点所在列是不是全为红色:
如果条件成立就是那个颜色。
注意蓝色只会涂水平列,红色只会涂水平行(没看到白wa一发qwq)。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
char s[9][9];

int pan(int x,int y)
{
    char ss=s[x][y];
    int pan=1;
    if(s[x][y]=='B'){
    for(int i  =1;i<=8;i++)
    if(s[i][y]!=s[x][y])pan=0;
    if(pan)return 1;
    else return 0;
    }
     pan=1;
    for(int i  =1;i<=8;i++)
    if(s[x][i]!=s[x][y])pan=0;
    if(pan)return 1;
    else return 0;

}


int main()
{
	int t ;
    cin>>t;
    while(t--)
    {
        for(int i =1;i<=8;i++)
        cin>>s[i]+1;
        char p;
        for(int i =1;i<=8;i++)
        {
            for(int j =1;j<=8;j++)
            {
                if(s[i][j]!='.'){
                    if(pan(i,j))
                   p=s[i][j];
                }
            }
        }
        cout<<p<<endl;
    }

	return 0;
}

D

题目大意:找出 i , j( 1<=i<=j<=n)使cnt[i]和cnt[j]的最大公约数为1
并且算出i+j最大时为多少。
思路:本来怎么想都想不通的,但是后来看到数组元素的范围小于1000,就想到了对数进行暴力:
首先用map存每个数出现的最大的下标
两重循环i,j,如果i和j的最大公约数为1,那么就不断比较i和j出现的最大的下标之和求出max即可。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N];

map<int,int>q;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		q.clear();
		cin>>n;
		for(int i =1;i<=n;i++)
		{
			int x;
			cin>>x;
			q[x]=max(q[x],i);
		}
		int res=-1;
		for(int i =1;i<=1000;i++)
		{
			for(int j =1;j<=1000;j++)
			{
				if(__gcd(i,j)==1&&q[i]!=0&&q[j]!=0){
				res=max(res,q[i]+q[j]);
				}
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

E

题目大意:给你一个n,然后给你第n个台阶的高度,之后给你q次询问,给你一个人的腿的长度x,只有当x的长度大于等于台阶的高度才能跨过当前的台阶,问你腿长度为x的人最长能走的最高的高度是多少。

思路:
首先,如果这个人要走到第n阶台阶的话,那么他前n阶台阶一定要都能走过(意思就是这个人的腿的长度大于等于前n阶台阶的高度)。

那么我们可以定义一个k数组用来存走到当前台阶需要的腿长,cnt存前n阶台阶的和。之后就可以二分答案直接做了。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N];
ll cnt[N];
ll k[N];
void erfen(ll x)
{
    int l =0,r=n,mid=0;
    while(r>l)
    {
        mid=l+r+1>>1;
        if(k[mid]<=x) l=mid;
        else r=mid-1;
    }
    cout<<cnt[r]<<" ";
    return ;
}

int main()
{
	int t ;
    cin>>t;
    while(t--)
    {

        memset(k,0,sizeof k);
        cin>>n>>m;
        for(int i =1;i<=n;i++){
            cin>>s[i];
            cnt[i]=cnt[i-1]+s[i];
            k[i]=max(k[i-1],s[i]);
        }
  
        for(int i =1;i<=m;i++)
        {
            ll x;
            cin>>x;
            erfen(x);
        }
        cout<<endl;

    }
	return 0;
}

F

**题意:**给你两个字符串s跟t,这两个字符串一开始只有’a’一个字符,
后来n次操作对s或者t进行增加字符串的操作,问你每次操作后能不能通过s和t的任意排序保证s的字典序小于t的字典序.

思路:因为s中一定会有一个 ’ a ’ ,那么只要t中出现非’a’的字符,就可以把它放到t的最前面使s<t
否则t中全为’a’的字符,那么要判断s的长度是否小于t的长度并且s中不能存在非’a’的字符(因为t中全是’a’如果s中有一个非’a’,就算放在最后面也是会大于t的)。
否则就不满足条件。
最后记得长度开long long 。(开int爆了n次)。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;

int cnt[200][3];
			ll a,b;
			char s[N];
int main()
{
	int t ;
	cin>>t;
	while(t--)
	{
		cin>>n;
		/*
		如果t出现非a的元素,就为YES
		否则,(t全为a的元素)首先字符串的长度要大于s,并且s中不能出现非a的元素才为YES,否则为NO
		*/
		int f=0,f1=0;
		ll sizea=0,sizeb=0;
		while(n--)
		{
			cin>>a>>b>>s;
			if(!f){
			if(a==1) sizea+=strlen(s)*b;
			else sizeb+=strlen(s)*b;
			}
			for(int i =0;i<strlen(s);i++)
			{
				if(a==2&&s[i]!='a'){//t有非a的元素
				f=1;
				}
				if(a==1&&s[i]!='a'){//t有非a的元素
				f1=1;
				}
			}
			if(f||(sizea<sizeb&&!f1)) cout<<"YES\n";
			else cout<<"NO\n";
		}
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值