Codeforces Round #366 (Div. 2) A 【水题】& B【博弈】 & C 【思维】

Codeforces Round #366 (Div. 2) A & B & C 【模拟】


A. Hulk


题目链接:http://codeforces.com/contest/705/problem/A

题意:根据给的n奇偶性输出 “hate” 和 “love”

#include <cstdio>
using namespace std;
int n;
int main(){
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            if(i%2)printf("I hate ");
            else printf("I love ");
            if(i!=n) printf(" that ");
        }
        printf("it\n");
    }
    return 0;
}


B. Spider Man【博弈论:先手赢】


题目链接:http://codeforces.com/contest/705/problem/B

题意: 两个人玩分圈的游戏,有n个圈,每个圈有m个点,每次你都可以对 点数m>1 的圈分成(m-x,x),若最后的圈都为1了轮到的这个人就不能动了,另外一个人赢了。

题解: 每个圈m 都可以分m-1,把n个圈的分次数加起来得到和sum,再对其做奇偶处理

#include <cstdio>
using namespace std;
typedef long long LL;
int n,m,k,t;
int main(){
    while(~scanf("%d",&n)){
        LL sum = 0;
        for(int i=1;i<=n;i++){
            scanf("%d",&m);
            sum+=m-1;
            if(sum%2)printf("1\n");
            else printf("2\n");
        }
    }
    return 0;
}

C. Thor【思维题】


题目链接:
题意:
手机里面n个消息,接下来 q个命令:【x y】
x==1 表示应用y生成了一个消息
x==2 读出了所有的由应用y产生的消息
x==3 读了前y个消息【注意:可能读了已读的消息,重复】
每次询问后 求手机里面未读的个数number

题解:按题意操作,主要是a为2、3时,两重for WA test4数据为300000 TLE:
应用y所产生的未读消息 a[y]
表示标记顺序状态 yi[y]
x==2,要标记状态yi[y] 并清空 所有应用y所产生的 未读 消息 a[y] = 0;
x==3,循环当前的y个数并判断其中有已读否的消息,此时可以剪下枝
再处理未读的消息就好

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define me(x) memset(x,0,sizeof(x));
typedef long long LL;
const int maxn = 400000;
int n,m,q;
int a[maxn];//未读 由应用y产生的消息个数
int b[maxn];
int yi[maxn];
int main(){
    while(~scanf("%d%d",&n,&q)){
        me(a);
        me(b);
        me(yi);// 标记yi[]=0为未读状态
        int num = 0;//未读消息个数
        int j = 1;
        int i = 0;//消息总个数
        while(q--){
            int x,y;
            scanf("%d %d",&x,&y);
            if(x==1){
                a[y]++; 
                num++;
                b[++i] = y;// 顺序
            }else if(x==2){
                yi[y] = i;// 标记,已读数y的顺序 
                num -= a[y];
                a[y] = 0;
            }else if(x==3){
                for(; j<=y ; j++){
                    if(yi[ b[j] ] < j){ //判断是否已读
                        a[b[j]]--;
                        num--;
                    }
                }
            }
            printf("%d\n",num);
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值