SDUT 2021 Winter Individual Contest - E // B、C、D、M

B - Pursuing the Happiness

题目链接:https://vjudge.net/contest/418211#problem/B

Mike wants to find a substring «happiness» in the string s, but Constantine cannot allow this and decidedto hinder him. He is planning to swap two characters on two different positions in the string s so that Mike wouldn’t be able to find what he looks for. Which two characters Constantine should swap?
Input
The only line contains from 2 to 2 · 105 lowercase Latin letters — the string s, in which Mike wants to
find a substring «happiness».
Output
If Constantine succeeds in achieving his goal, in the first line output «YES» without quotes. In the second line output two distinct integers separated by a space — the positions of characters in the string s, which Constantine should swap. Positions in the string are numbered from one. If there are several possible answers, output any of them.
If for any choice of Constantine Mike still would be able to find a substring «happiness», in the only line output «NO» without quotes.
Examples

standard input
pursuingthehappiness
standard output
YES
15 18

standard input
happinessformehappinessforyouhappinessforeverybodyfreeandletnoonebeleftbehind
standard output
NO

大意:M 想在字符串中找 happiness ,C 想交换两个字符(位置不同)让 M 找不到 happiness ,如果还能找到输出 NO ,找不到输出 YES 和 两个字符的位置
题解:当 happiness 的个数 >=3 的时候输出 NO ; 个数 =0 的时候,随意交换可能会导致它出现 happingess !!.

#include <bits/stdc++.h>
using namespace std;
string a,b="happiness";
int main()
{
    ios::sync_with_stdio(false);
    cin>>a;
    int n=a.size(),num=0,v1=0,v2=0;
    for(int i=0; i<=n-9; i++)
    {
        string x=a.substr(i,9);
        if(x==b)
        {
            num++;
            if(num==1) v1=i+1;
            if(num==2) v2=i+6;
            if(num>=3)
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    if(num==0)
    {
        int t=a[0];
        a[0]=a[1];
        a[1]=t;
        for(int i=0; i<=n-9; i++)
        {
            string x=a.substr(i,9);
            if(x==b)
            {
                cout<<"YES"<<endl;
                cout<<"1 3"<<endl;
                return 0;
            }
        }
        cout<<"YES"<<endl;
        cout<<"1 2"<<endl;
    }
    else if(num==1)
    {
        cout<<"YES"<<endl;
        cout<<v1<<" "<<v1+1<<endl;

    }
    else if(num==2)
    {
        cout<<"YES"<<endl;
        cout<<v1<<" "<<v2<<endl;
    }
    return 0;
}

D - Jumps

原题链接:https://vjudge.net/contest/418211#problem/D

A frog lives in a one-dimensional world in the point with the coordinate 0. He needs to get to the point with the coordinate x. For some reason he cannot make jumps of arbitrary length, and can jump only by a1, …, an in any direction. Is he able to reach x?

Input
The first line contains two integers n and x separated by a space (1 ≤ n ≤ 200000,  - 109 ≤ x ≤ 109) — the number of variants of jump length and the coordinate of the point to reach.

The second line contains n integers ai separated by spaces (1 ≤ ai ≤ 109) — the lengths of jumps the frog can make.

Output
Output «YES» (without quotes), if the frog can reach the point x, otherwise output «NO» (without quotes).

Examples

Input
3 17
3 5 4
Output
YES

Input
4 5
10 20 30 40
Output
NO

题意:水平方向上有一只青蛙 想去位置为 x 的地方,但它一次只能跳 a[i]
题解:
也就是 cnt1*a[0] + cnt2*a[1] = x
根据扩展欧几里得算法 :ax + by = gcd(a,b)
所以 x = gcd ( a[0] , a[1] )

题解参考

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,gg,a;
    ios::sync_with_stdio(false);
    cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(i==0) gg=a;
        gg=__gcd(gg,a);
    }
    if(x%gg==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

C - Urn with Balls

题目链接:https://vjudge.net/contest/418211#problem/C

箱子里有 a个红球 b个绿球 和 c个可能是绿色也可能是红色的球
现在从箱子中取出 <=n 的红球和 <=m 的绿球
最多能取多少个

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    long long int a,b,c,m,n;
    cin>>a>>b>>c>>m>>n;

//    long long int ans=a+b+c;
//    if(a+c>m) ans=m;
//    if(b+c>n) ans=min(ans,n);
//    cout<<ans;

    if(a+c>m&&b+c>n) cout<<min(n,m)<<endl;
    else if(a+c<=m&&b+c>n) cout<<n<<endl;
    else if(b+c<=n&&a+c>m) cout<<m<<endl; 
    else if(a+c<=m&&b+c<=n) cout<<a+b+c<<endl;

    return 0;
}

M - Last Man Standing

https://vjudge.net/contest/418211#problem/M
A company of n friends decided to play a multiplayer shooter in the Last Man Standing mode. The distinctive feature of this mode is when a player is killed, he does not respawn, but waits a round to finish. A round finishes when there is only one player alive.

You are given a notarized screenshot of the current fight results, made during the first round of the game. It provides an information about how many kills each player has made. You want to check if it’s a fake or not, i.e. whether such situation could occur during the game.

Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of players.

The second line contains n integers ai separated by a space (0 ≤ ai ≤ 109) — the numbers of kills made by each player. These numbers are given in non-increasing order.

Output
If such situation was not possible in the game, output «NO» (without quotes).

Otherwise, in the first line output «YES» (without quotes), and then output a log of kills in the round, consisting of k pairs of integers, where k is the total number of kills made at the moment of taking the screenshot. Each pair of integers in the log must consist of the number of the player who made the kill, and the number of the killed player, exactly in this order. Records in the log must be ordered chronologically. If there are several correct logs, output any of them.

Examples
Input

5
2 1 1 0 0
Output
YES
3 5
2 4
1 3
1 2

Input
7
3 2 2 0 0 0 0
Output
NO

Input
1
0
Output
YES

Input
3
1 0 0
Output
YES
1 3

比赛的时候没审好题,说要按照时间顺序来 先被杀的在前边
再就是sum超int,显示 time limit exceeded。。。

#include <bits/stdc++.h>
using namespace std;
long int a[200005]={0},m=1;
long int st[200005];
long int x[200005],y[200005],num=0;
//void f1()
//{
//    int top=1,tail=2;
//    while(top<=m)
//    {
//        while(a[top]--)
//        {
//            x[num]=top;
//            y[num++]=tail;
//            cout<<top<<" "<<tail<<endl;
//            ++tail;
//        }
//        top++;
//    }
//}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    long long int sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>0) m++;
        sum+=a[i];
    }
    if(sum>=n) cout<<"NO"<<endl;
    else
    {
        cout<<"YES"<<endl;
        int cnt=2;
        for(int i=1;i<m;i++)
        {
            for(int j=0;j<a[i];j++)
            {
                x[num]=i;
                y[num++]=cnt++;
            }
        }
        for(int i=num-1;i>=0;i--)
            cout<<x[i]<<" "<<y[i]<<endl;
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值