1729E - Guess the Cycle Size - CodeForces Solution


interactive probabilities

Please click on ads to support us..

Python Code:

import random
def contains(x,l):
	if(len(l) == 0):
		return False
	for i in l:
		if(x == i):
			return True
	return False
q = 50 
min_val = 1
max_val = 3
a = random.randint(min_val,max_val)
b = random.randint(min_val,max_val)
l = []
ans = 0
fin_ans = 0
while(q > 0):
	a = random.randint(min_val,max_val)
	b = random.randint(min_val,max_val)
	x = (a,b)
	while(a == b or (contains(x,l) or contains((x[1],x[0]),l))):
		a = random.randint(min_val,max_val)
		b = random.randint(min_val,max_val)
		x = (a,b)
	print("?",a,b)
	ans = int(input())
	if(ans == -1):
		max_val = max(a,b)
		q = q - 1
	else:
		l.append(x)
		l.append((x[1],x[0]))
		print("?",b,a)
		ans2 = int(input())
		if(ans != ans2):
			fin_ans = ans + ans2
			break
		max_val = max(max_val,1 + max(ans2,ans))
		q = q - 2
	print("!",fin_ans)

C++ Code:

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    i64 a = 1, b = 2;
    while (true) {
        std::cout << "? " << a << " " << b << std::endl;
        i64 x;
        std::cin >> x;
        
        std::cout << "? " << b << " " << a << std::endl;
        i64 y;
        std::cin >> y;
        
        if (x == -1 || y == -1) break;
        if (x != y) {
            std::cout << "! " << (x + y) << std::endl;
            break;
        }
        a += 1, b += 1;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh
1721E - Prefix Function Queries
977E - Cyclic Components
1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist