Codeforces Round #366 (Div. 2)题解报告

来源:互联网 发布:淘宝店铺装修添加宝贝 编辑:程序博客网 时间:2024/05/17 06:38

此文章可以使用目录功能哟↑(点击上方[+])

题目区分得有点明显呀,简单的题做出的人很多,难题就没多少人做了,不过我这个赛后做的也就不多言了...

链接→Codeforces Round #366 (Div. 2)

 Problem A - Hulk

Accept: 0    Submit: 0
Time Limit: 1 second    Memory Limit : 256 megabytes

 Problem Description

Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.

Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, second one is love, third one is hate and so on...

For example if n = 1, then his feeling is "I hate it" or if n = 2 it's "I hate that I love it", and if n = 3 it's "I hate that I love that I hate it" and so on.

Please help Dr. Banner.

 Input

The only line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of layers of love and hate.

 Output

Print Dr.Banner's feeling in one line.

 Sample Input

1
2
3

 Sample Output

I hate it
I hate that I love it
I hate that I love that I hate it

 Problem Idea

解题思路:

【题意】
当n = 1时,输出"I hate it";

当n = 2时,输出"I hate that I love it";

当n = 3时,输出"I hate that I love that I hate it";

以此类推.


【类型】
规律

【分析】
一道水规律

从样例就可以看出,结果为


【时间复杂度&&优化】
O(n)

题目链接→Codeforces 705A Hulk

 Source Code

/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 100005;const int M = 16;const int inf = 1000000007;const int mod = 110119;int main(){    int n,i;    scanf("%d",&n);    printf("I hate");    for(i=1;i<n;i++)    {        printf(" that I ");        if(i%2)            printf("love");        else            printf("hate");    }    puts(" it");    return 0;}

 Problem B - Spider Man

Accept: 0    Submit: 0
Time Limit: 2 seconds    Memory Limit : 256 megabytes

 Problem Description

Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.

Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle withat least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).

Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?

Peter is pretty good at math, but now he asks you to help.

 Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 10^9), i-th of them stands for the number of vertices in the cycle added before the i-th test.

 Output

Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.

 Sample Input

3
1 2 3
5
1 1 5 1 1

 Sample Output

2
1
1
2
2
2
2
2

 Problem Idea

解题思路:

【题意】
题目有点长,不太好理解,所以还是直接看Note吧

就是n个环,每个环有ai个结点,Peter Parker和Dr. Octopus博弈,Peter Parker先手

当环内结点数>1时,可将该环分成两个环,分别为k个结点和ai-k个结点

问随着环数的增加,谁会赢?Peter Parker赢输出"1";否则输出"2"


【类型】
简单博弈

【分析】
Note
In the first sample test:
In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.
In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can't make any move and loses.
In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1, 1, 2, 2 vertices. Second player's only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size 1 and wins.
In the second sample test:
Having cycles of size 1 is like not having them (because no one can make a move on them).
In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2 and 3.

  • If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can't make any move and loses.
  • If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins.
So, either way first player loses.

首先我们要知道,一个环不可再分,当且仅当该环内只有一个结点,那对于有n个结点的环要分几次才能不可再分呢?

举例发现,不管你怎么分,n个结点的环要分n-1次才能不可再分

这样就简单了,我们对可分次数求一下和,再判一下奇偶性就可以得到答案了

【时间复杂度&&优化】
O(n)

题目链接→Codeforces 705B Spider Man

 Source Code

/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 100005;const int M = 16;const int inf = 1000000007;const int mod = 110119;int main(){    int n,s,i;    __int64 ans=0;    scanf("%d",&n);    for(i=0;i<n;i++)    {        scanf("%d",&s);        ans+=s-1;        if(ans%2)            puts("1");        else            puts("2");    }    return 0;}

 Problem C - Thor

Accept: 0    Submit: 0
Time Limit: 2 seconds    Memory Limit : 256 megabytes

 Problem Description

Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

q events are about to happen (in chronological order). They are of three types:

  1. Application x generates a notification (this new notification is unread).
  2. Thor reads all notifications generated so far by application x (he may re-read some notifications).
  3. Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation.

Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

 Input

The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.

The next q lines contain the events. The i-th of these lines starts with an integer typei — type of the i-th event. If typei = 1 or typei = 2 then it is followed by an integer xi. Otherwise it is followed by an integer ti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).

 Output

Print the number of unread notifications after each event.

 Sample Input

3 4
1 3
1 1
1 2
2 3
4 6
1 2
1 4
1 2
3 3
1 3
1 3

 Sample Output

1
2
3
2
1
2
3
0
1
2

 Problem Idea

解题思路:

【题意】
有三类操作:

①app x 产生一条未读消息

②将到目前为止app x产生的未读消息标为已读

③把前t条消息(包括已读消息)标为已读


【类型】
暴力

【分析】
Note
In the first sample:

  1. Application 3 generates a notification (there is 1 unread notification).
  2. Application 1 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
  1. Application 2 generates a notification (there is 1 unread notification).
  2. Application 4 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
  5. Application 3 generates a notification (there is 1 unread notification).
  6. Application 3 generates a notification (there are 2 unread notifications).

用数组application[i]表示app i 到目前为止产生的未读消息

position[i]表示第i条消息在哪一次操作产生

belong[i]表示第i次操作属于哪个app(当然,只有操作①才有归属,操作②和操作③该值为0)

clear[i]表示,app i产生的消息在哪一次操作被标为已读

success表示前多少条消息已经全被标为已读

剩下的就是一波暴力模拟

【时间复杂度&&优化】
O(n)

题目链接→Codeforces 704A Thor

 Source Code

/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 300005;const int M = 16;const int inf = 1000000007;const int mod = 110119;int success,application[N],position[N],belong[N],clear[N];int main(){    int n,q,i,j,type,x,k=1,ans=0;    scanf("%d%d",&n,&q);    for(i=1;i<=q;i++)    {        scanf("%d%d",&type,&x);        if(type==1)            belong[i]=x,application[x]++,position[k++]=i,ans++;        else if(type==2)            ans-=application[x],application[x]=0,clear[x]=i;        else        {            x=position[x];            if(success<x)            {                for(j=success;j<=x;j++)                    if(belong[j]&&clear[belong[j]]<j)                        application[belong[j]]--,ans--,clear[belong[j]]=j;                success=x;            }        }        printf("%d\n",ans);    }    return 0;}

菜鸟成长记

0 0
原创粉丝点击