Codeforces Educational Round 27 总结

这一场打的还不错2333…7题A了5题,还去hack了18个人…排名在65…Fighting!!!

A. Chess Tourney

题意: 2n 个棋手准备来一起比赛,每个人有一个能力值 a[i] ,他们被分为两个组,每一组有 n 个人。两组之间的比赛是从两组里面随机挑一个人进行比赛,能力值高的人获胜。问有没有一种分组方法,使不管怎么比赛,第一组所有队员都能获胜。有输出Yes,否则输出 No
思路&&题解:首先可以肯定,先将能力值从大到小排序,前 n 个选手肯定都是分在第一组的,而要判断是否所有人都能获胜,只用判断a[n]是否等于 a[n+1] 就行了。

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int maxn=205;
int n;
int a[maxn];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n*2+1);
    if(a[n]==a[n+1])
        puts("NO");
    else
        puts("YES");
    return 0;
}

B. Luba And The Ticket

题意:给你一串长度为 6 且仅由数字组成的字符串,如果该字符串前三位数字和与后三位数字和相等,则这一串字符串就是幸运的,问最少改动几个数字使原串变为幸运的字符串。
思路&&题解:因为字符串长度只有6,所以只要从 0999999 枚举一遍就行了,如果这个数字是幸运的,那么判断一下他与原串有几位数字不相同,跟 ans 取个 min 就行了。

代码如下:

#include<bits/stdc++.h> 
using namespace std;
string s;
int t[6];
int d[6];
int db,mini;
int main() {
    cin>>s;
    for(int i=0;i<6;i++)
        t[i]=s[i]-'0';
    mini=6;
    for(int i=0;i<1000000;i++){
        db=i;
        for(int j=0;j<6;j++){
            d[j]=db%10;
            db/=10;
        }
        if(d[0]+d[1]+d[2]==d[3]+d[4]+d[5]){
            db=0;
            for(int j=0;j<6;j++){
                if(t[j]!=d[j])
                    db++;
            }
            mini=min(mini,db);
        }
    }
    cout<<mini<<endl;
    return 0;
}

C. two TVs

有一个人想要看 n 个他喜欢的电视节目,每个节目都有一个l,r,表示节目开始时间与节目结束时间。如果两个节目的时间有重复,那么只能在两台不同的电视上播放,问有没有一种可行的方案,使得这 n 个节目可以在两台电视上播放完。可以输出Yes,否则输出 No
思路&&题解:其实只要用一个 pair<int,int> 数组,就可以通过这题。对于每次读进来的 l,r ,我们在数组中加入 l,1 表示在时刻 l 又有一个新的节目开始播放,再加入r+1,1,表示在时刻 r+1 有一个节目已经放完。最后根据 pair first 排序一遍,然后扫一遍,用 cnt 加上 pair second ,如果其中有个时刻 cnt>2 那就输出 No ,否则就是 Yes

代码如下:

#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >pro;
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        int l,r;
        scanf("%d%d",&l,&r);
        pro.push_back(make_pair(l,1));
        pro.push_back(make_pair(r+1,-1));
    }
    sort(pro.begin(),pro.end());
    int cnt=0;
    for(int i=0;i<pro.size();i++) {
        cnt+=pro[i].second;
        if(cnt>2) { 
            printf("NO\n");
            return 0;
        } 
    }
    printf("YES\n");
    return 0;
}

D. Driving Test

题意:一位学员正在学车,他一共有 n 个操作,第i个操作有一个 type ,如果 type=1 ,那么再读入一个数 x ,表示他将自己的车速提到了x;如果 type=2 ,那么表示他超过了一辆车;如果 type=3 ,那么再读入一个数 x ,表示他经过了一个限速不超过x的标志;如果 type=4 ,表示他经过了“可以超车”的标志;如果 type=5 ,表示他经过了“不限速”的标志;如果 type=6 ,表示他经过了一个“不允许超车”的标志。现在给出你 n 个操作,问该学员需要说自己至少没有看到几个标志才能不违反规则。
思路&&题解:这是一道模拟题,对于1操作,将前面的 3 标志读入的限速从后往前扫一遍,直到扫到一个限速大于现在的速度,扫过几个,就当他没看到那几个标志。对于2操作,将前面最后一个 4 操作之后的6的个数且没有已经被忽略过的个数加上就行了。后面的几个操作也根据定义模拟就行了。

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int maxn=200050;
int type;
int n;
int nowlimit=999;
int nowspeed=999;
bool over=1;
int tot=0,overtot=0;
int lim[maxn],o=0;
bool vis[maxn];
int main() {
    lim[0]=999;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",&type);
        if(type==1) {
            scanf("%d",&nowspeed);
            if(o==0)
                continue;
            while(lim[o]<nowspeed&&o>0) {
                o--;
                tot++;
            }
        }
        else if(type==2) {
            if(!over) {
                tot+=overtot;
                overtot=0;
            }
        }
        else if(type==3) {
            scanf("%d",&nowlimit);
            if(nowlimit<nowspeed)
                tot++;
            else {
                o++;
                lim[o]=nowlimit;
            }
        }
        else if(type==4) {
            over=1;
        }
        else if(type==5) {
            o=0;
        }
        else if(type==6) {
            if(over) {
                over=0;
                overtot=1;
            }
            else
                overtot++;
        }
    }
    while(lim[o]<nowspeed&&o>0) {
        o--;
        tot++;
    }
    printf("%d\n",tot);
    return 0;
}

E. Fire in the City

暂时还未看过题,先放一放…

F. Guards In The Storehouse

暂时还未看过题,先放一放…

G. Shortest Path Problem?

题意:给你 n 个点和m条边(允许有重边和自环),求 1n 的路径长度最小(路径长度为所经过边权xor和)。
思路&&题解:所有路径实际是一条1-n的路径和一堆环,而环可以用 dfs 求出…然后就是高斯消元的应用了233…
P.S.该题与 BZOJ2115 非常相似,只是一个求最小一个求最大罢了233…

代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read() {
    ll x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
int n,m,cnt,cir,tot;
int last[100005];
ll bin[65],v[500005],d[100005];
bool vis[100005];
struct node {
    int to,next;
    ll v;
}e[200005];
void insert(int u,int v,ll w) {
    e[++cnt].to=v;
    e[cnt].next=last[u];
    last[u]=cnt;
    e[cnt].v=w;
    e[++cnt].to=u;
    e[cnt].next=last[v];
    last[v]=cnt;
    e[cnt].v=w;
}
void dfs(int x) {
    vis[x]=1;
    for(int i=last[x];i;i=e[i].next)
        if(!vis[e[i].to]) {
            d[e[i].to]=d[x]^e[i].v;
            dfs(e[i].to);
        }
        else
            v[++cir]=d[x]^d[e[i].to]^e[i].v;
}
void gauss() {
    for(ll i=bin[60];i;i>>=1) {
        int j=tot+1;
        while(j<=cir&&!(v[j]&i))
            j++;
        if(j==cir+1)
            continue;
        tot++;
        swap(v[tot],v[j]);
        for(int k=1;k<=cir;k++)
            if(k!=tot&&(v[k]&i))
                v[k]^=v[tot];
    }
}
int main() {
    bin[0]=1;
    for(int i=1;i<=60;i++)
        bin[i]=bin[i-1]<<1;
    n=read();
    m=read();
    for(int i=1;i<=m;i++) {
        int u=read(),v=read();
        ll w=read();
        insert(u,v,w);
    }
    dfs(1);
    gauss();
    ll ans=d[n];
    for(int i=1;i<=tot;i++)
        ans=min(ans,ans^v[i]);
    printf("%lld\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值