码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #562 (Div. 2)

时间:2019-07-09 00:39:04      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:with   个数   通过   from   insert   asi   body   accept   sizeof   

A

 

题意:两条循环线路,一条是递增,逐次增加1,到最大和最小的相邻;另一条线路递减,同前的规律。看他们是否会在同一时间,经过同一个站点

其实是一个水题,题目开始时读错了,wa了几发,还浪费了时间qwq,

 

B. Pairs

题意:判断是否存在两个x,y ,使x,y至少有一个是在这些实数对中的;

题目的意思很简单,第一对a1,b1中,肯定至少有一个数是在x,y;分两种情况,1:x=a1,在不含x的实数对中找y ; 2:x=b1,在不含x的实数对中找y ;只要两种情况中有一种符合条件即可

技术图片
/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
 
 
#include <bits/stdc++.h>
#include <iostream>
 
using namespace std;
 
#define  ll long long
const int maxn=5e5+5;
const int maxn1=(int)sqrt(maxn)+1;
int a[maxn],b[maxn];
set<int> s;
set<int>::iterator it;
int main(){
    std::ios::sync_with_stdio (false);
    int n,x,y,m,flag=1;
    cin>>x>>y;
    for(int i=1; i<=y; ++i) cin>>a[i]>>b[i];
  //第一种情况
    for(int i=2; i<=y; ++i){
        if(a[i]!=a[1]&&b[i]!=a[1]){//在不含x的实数对中找y 
            if(s.empty()) s.insert(a[i]),s.insert(b[i]);
            else {
                //cout<<i<<" "<<s.count(a[i])<<" "<<s.count(b[i])<<endl;
                //cout<<endl;
                if(s.count(a[i])&&s.count(b[i])) continue;
                else if(s.count(a[i])){
                    for(it=s.begin(); it!=s.end(); ++it)
                    if(*it!=a[i]){
                        s.erase(it);
                        break;
                    }
                }
                else if(s.count(b[i])){
                    for(it=s.begin(); it!=s.end(); ++it)
                    if(*it!=b[i]){
                        s.erase(it);
                        break;
                    }
                }
                else {
                    flag=0;
                    break;
                }
            }
        }
    }
    if(flag){
        cout<<"YES";
        return 0;
    }
  
  //第二种情况
    s.clear(),flag=1;
    for(int i=2; i<=y; ++i){
        if(a[i]!=b[1]&&b[i]!=b[1]){//在不含x的实数对中找y 
            if(s.empty()) s.insert(a[i]),s.insert(b[i]);
            else {
                if(s.count(a[i])&&s.count(b[i])) continue;
                else if(s.count(a[i])){
                    for(it=s.begin(); it!=s.end(); ++it)
                    if(*it!=a[i]){
                        s.erase(it);
                        break;
                    }
                }
                else if(s.count(b[i])){
                    for(it=s.begin(); it!=s.end(); ++it)
                    if(*it!=b[i]){
                        s.erase(it);
                        break;
                    }
                }
                else {
                    flag=0;
                    break;
                }
            }
        }
    }
    if(flag){
        cout<<"YES";
        return 0;
    }
    else cout<<"NO";
    return 0;
}
View Code

 

C. Increasing by Modulo

题意:通过n次操作是序列不递减,操作:对可以对序列中的任意个数ai ---> ai=(ai+1)mod m;

看题解才知道的,对操作数二分,找出最小满足条件的序列即可,太强了qwq,注意条件的判断

对操作数二分,太神奇了。

a:不知道做,有想法,没办法,

b:按要求结果暴力啊

a:超时了qwq

b:神马,超时,暴力+二分

qwq

技术图片
/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
 
 
#include <bits/stdc++.h>
#include <iostream>
 
using namespace std;
 
#define  ll long long
const int maxn=5e5+5;
const int maxn1=(int)sqrt(maxn)+1;
int a[maxn],b[maxn],low[maxn];
set<int> s;
set<int>::iterator it;
int n,m;
bool check(int k){
    memset(low,0,sizeof(low));
    for(int i=1; i<=n; ++i){
        if(low[i-1]==a[i]) {
            low[i]=low[i-1];
            continue;
        }
        int tmp=(a[i]+k)%m;
        if((a[i]<low[i-1]&&tmp>=a[i]&&tmp<low[i-1]))
            return false;
        if((a[i]>low[i-1]&&(tmp>=a[i]||tmp<low[i-1]))){
            low[i]=a[i];}
        else low[i]=low[i-1];
        //cout<<i<<" "<<low[i]<<endl;
    }
    return true;
}
 
 
int main(){
    std::ios::sync_with_stdio (false);
    int flag=1;
    cin>>n>>m;
    for(int i=1; i<=n; ++i) cin>>a[i];
    int l=0,r=m;
    int ans=0;
    while(l<=r){
        //cout<<l<<" "<<r<<" "<<ans<<endl;
        int mid=(l+r)>>1;
        if(check(mid)) {
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
 
    }
    cout<<ans<<endl;
    return 0;
}
View Code

 

D. Good Triple

wa声一遍,写出来了再来写

 

思路清晰,在纸上模了一遍,写代码时,就会少一些bug

Codeforces Round #562 (Div. 2)

标签:with   个数   通过   from   insert   asi   body   accept   sizeof   

原文地址:https://www.cnblogs.com/mrdushe/p/11154624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!