GVKun编程网logo

Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法)

8

以上就是给各位分享CodeforcesRound#435(Div.2)B.MahmoudandEhabandthebipartiteness(二分图,染色法),同时本文还将给你拓展B类-Codefor

以上就是给各位分享Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法),同时本文还将给你拓展B类-Codeforces Round #535 (Div. 3)C. Nice Garland、Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map、Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))、Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法)

Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法)

总结

以上是小编为你收集整理的Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法)全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

B类-Codeforces Round #535 (Div. 3)C. Nice Garland

B类-Codeforces Round #535 (Div. 3)C. Nice Garland

Codeforces Round #535 (Div. 3)C. Nice Garland

题意:

R‘,‘G‘ and ‘B‘ 三个字母组成的一个字符串,每两个相同的字母需要相差3,找出最小需要交换次数。

分析:

这个字符串的长度大于等于3的时候,一定是RBG这三个字符的某一个排列的循环。
RBG一共最多有6种排列方式{"RGB","RBG","BGR","BRG","GRB","GBR"};

所以直接暴力循环6次即可。

代码:

#include<iostream>
using namespace std;
string dir[6]={"RGB","RBG","BGR","BRG","GRB","GBR"};
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int minn=100000000;
    int flag=0;
    //cout<<dir[5][1];
    for(int j=0;j<6;j++){
        int count=0;
        for(int i=0;i<n;i+=3){
            if(s[i]!=dir[j][0]) count++;
            if(i+1 >= n)
            break;
            else if(s[(i+1)]!=dir[j][1]) count++;
            if(i+2 >= n)
            break;
            else if(s[(i+2)]!=dir[j][2]) count++;
        }
        if(count<minn){
            minn=count;
            flag=j;
        }
    }
    cout<<minn<<endl;
    int i;
    for(i=0;i + 3 <n;i+=3){
        cout<<dir[flag];
    }
    int j = 0;
    for(i;i < n;i++)
    cout << dir[flag][j++];
    
    //if(n%3==)
    return 0;
}//比赛结束了几分钟才改好,emmmmmmm,笨死啦。

Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map

Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map

总结

以上是小编为你收集整理的Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))

Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))

D. Game with modulo
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

Vasya and Petya are going to play the following game: Petya has some positive integer number aa. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers (x,y)(x,y). Petya will answer him:

  • "x", if (xmoda)(ymoda)(xmoda)≥(ymoda).
  • "y", if (xmoda)<(ymoda)(xmoda)<(ymoda).

We define (xmoda)(xmoda) as a remainder of division xx by aa.

Vasya should guess the number aa using no more, than 60 questions.

It''s guaranteed that Petya has a number, that satisfies the inequality 1a1091≤a≤109.

Help Vasya playing this game and write a program, that will guess the number aa.

Interaction

Your program should play several games.

Before the start of any game your program should read the string:

  • "start" (without quotes) — the start of the new game.
  • "mistake" (without quotes) — in the previous game, you found the wrong answer. Your program should terminate after reading this string and it will get verdict "Wrong answer".
  • "end" (without quotes) — all games finished. Your program should terminate after reading this string.

After reading the string "start" (without quotes) the new game starts.

At the beginning, your program should ask several questions about pairs of non-negative integer numbers (x,y)(x,y). You can only ask the numbers, that satisfy the inequalities 0x,y21090≤x,y≤2⋅109. To ask a question print "? x y" (without quotes). As the answer, you should read one symbol:

  • "x" (without quotes), if (xmoda)(ymoda)(xmoda)≥(ymoda).
  • "y" (without quotes), if (xmoda)<(ymoda)(xmoda)<(ymoda).
  • "e" (without quotes) — you asked more than 6060 questions. Your program should terminate after reading this string and it will get verdict "Wrong answer".

After your program asked several questions your program should print the answer in form "! a" (without quotes). You should print the number aa satisfying the inequalities 1a1091≤a≤109. It''s guaranteed that Petya''s number aa satisfied this condition. After that, the current game will finish.

We recall that your program can''t ask more than 6060 questions during one game.

If your program doesn''t terminate after reading "mistake" (without quotes), "end" (without quotes) or "e" (without quotes), it can get any verdict, because it will continue reading from closed input. Also, if your program prints answer or question in the incorrect format it can get any verdict, too. Be careful.

Don''t forget to flush the output after printing questions and answers.

To flush the output, you can use:

  • fflush(stdout) in C++.
  • System.out.flush() in Java.
  • stdout.flush() in Python.
  • flush(output) in Pascal.
  • See the documentation for other languages.

It''s guaranteed that you should play at least 11 and no more than 100100 games.

Hacks:

In hacks, you can use only one game. To hack a solution with Petya''s number aa (1a1091≤a≤109) in the first line you should write a single number 11 and in the second line you should write a single number aa.

Example
input
Copy
start
x
x
start
x
x
y
start
x
x
y
y
end
output
Copy
? 0 0
? 10 1
! 1
? 0 0
? 3 4
? 2 5
! 2
? 2 4
? 2 5
? 3 10
? 9 1
! 3
Note

In the first test, you should play 33 games with Petya''s numbers 11, 22 and 33.

In the first game, Petya will answer "x" (without quotes) to any question, because (xmod1)=0(xmod1)=0 for any integer xx.

In the second game, if you will ask pair (0,0)(0,0), the answer will be "x" (without quotes), because (0mod2)(0mod2)(0mod2)≥(0mod2). But if you will ask pair (2,5)(2,5), the answer will be "y" (without quotes), because (2mod2)<(5mod2)(2mod2)<(5mod2), because (2mod2)=0(2mod2)=0 and (5mod2)=1(5mod2)=1.

 

 

 

题意就是猜数,通过x和y猜取模的数a,就类似于猜钱,假设我有钱,但是具体数量只有我知道,我的好友来猜,他说我的钱数在1块和2块之前,我说不对,然后猜在2块和4块之间,不对,然后。。。猜在50到100之间,对的,继续,在75到50之间,对的,然后继续,缩小范围,最后就找到了。就是二分的思路。

我写的时候wa了一面交题记录。。。各种错误,二分太挫了,最后发现是初始值放错位置了,这还写什么鬼代码。。。

 

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=1e5+10;
 5 
 6 int main()
 7 {
 8     char ch[10],op[5];
 9     while(cin>>ch){
10         if(ch[0]!=''s'') break;
11         ll x=1,y=2;
12         while(true){
13             cout<<"? "<<x<<" "<<y<<endl;
14             cin>>op;
15             if(op[0]==''x'') break;
16             x=y,y=y*2;
17         }
18         ll l=x,r=y,mid;
19         while(l<r-1){
20             mid=(l+r)>>1;
21             cout<<"? "<<mid<<" "<<l<<endl;
22             cin>>op;
23             if(op[0]==''x'') l=mid;
24             else r=mid;
25         }
26         cout<<"? "<<r<<" "<<l<<endl;
27         cin>>op;
28         if(op[0]==''x'') cout<<"! "<<l<<endl;
29         else cout<<"! "<<r<<endl;
30         fflush(stdout);
31     }
32     return 0;
33 }

 

 

 

...

Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic

Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic

总结

以上是小编为你收集整理的Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

关于Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(二分图,染色法)的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于B类-Codeforces Round #535 (Div. 3)C. Nice Garland、Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map、Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))、Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic等相关知识的信息别忘了在本站进行查找喔。

本文标签: