ural 2063. Black and White

2063. Black and White

Time limit: 1.0 second
Memory limit: 64 MB

Let’s play a game. You are given a row of n balls, each ball is either black or white. Their positions in a row are numbered from 1 to n. You know the total number of balls n, but have no information about the order of their colors. You don’t even know how many white balls are there.

You are allowed to make queries v u (1 ≤ vu ≤ n). If the ball on position v is black and the ball on position u is white, then these two balls are swapped. Otherwise, nothing happens. Even if the balls are swapped, you don’t get any feedback.

After a number of queries (can be zero) you a required to make a "statement." "Statement" also consists of two positions vu. Your goal is to choose positions, that contain two balls of the same color.

In this problem we ask you to print both queries and a "statement", that comes after them.

A single test can contain several games. Furthermore, all tests except the first one contain 99 game descriptions. In the first game n = 2, in the second — n = 3 ... in the last game n = 100.

First test is the same as the sample below.

In all other tests your program must make the right statement at least in 80 games.

Note, that we do not guarantee that the tests are random.

Input

First line contains m — number of games in the test. For every test, except for the first one,m=99.

Remaining lines contain ciphered (except for the first test) order of balls in the row. Thus we guarantee, that the tests are determined beforehand and do not depend on your strategy. Please, do not try to use this data in any way and do not try to decipher it.

Output

Output m game descriptions.

One description consists of (k+1) lines, where k — number of queries made by your program.

First k lines should contain the queries in the following format: ? v u (1 ≤ vu ≤ nv ≠ u).

The last line should contain the "statement": ! v u (1 ≤ vu ≤ nv ≠ u).

Total amount of lines (over all games in a test) should not exceed 5 · 105.

Sample

input output
2
01
101
? 1 2
? 2 1
? 1 2
! 2 1
? 1 2
? 3 1
! 1 2

Notes

In the sample test white balls are marked as 0, black ones — as 1. Let’s examine the sample closely.

First game: 01 → 01 → 10 → 01 — we did not guess correctly.

Second game: 101 → 011 → 110 — we guessed correctly.

In this test we have guessed correctly in one game out of two.

Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2015

Tags: unusual problem  (hide tags for unsolved problems)

Difficulty: 421

题意:有n个球,要么0,要么1,你先进行若干次操作,选择u,v,如果a[u]<a[v],那么他们交换

以上操作无任何反馈

最后进行一个论断:你选择两个你认为相等的位置输出

正确80%以上即可。

分析:首先我们可以都过交换操作来个冒泡之类的排序

然后随机选择两个相邻的点,正确率为(n-2)/(n-1)

总的正确率80%应该没问题。

 1 #include <iostream>
 2 #include <ctime>
 3 #include <cstdlib>
 4 using namespace std;
 5
 6 int n;
 7
 8 int main()
 9 {
10     ios::sync_with_stdio(0);
11     srand(time(0));
12     int m;
13     cin >> m;
14     for(int n = 2; n <= m + 1; n++)
15     {
16         for(int i = 2; i <= n; i++)
17             for(int j = 1; j < i; j++)
18                 cout << "? " << j << ‘ ‘ << i << "\n";
19         int x = rand() % (n - 1) + 1;
20         cout << "! " << x << ‘ ‘ << x + 1 << "\n";
21         cout.flush();
22     }
23     return 0;
24 }

时间: 2024-11-05 17:02:05

ural 2063. Black and White的相关文章

URAL 1167. Bicolored Horses (DP)

题目链接 题意 :农夫每天都会放马出去,然后晚上把马赶入马厩,于是让马排成一行入马厩,但是不想马走更多的路,所以让前p1匹入第一个马厩,p2匹马入第二个马厩…………但是他不想让他的任何一个马厩空着,所有的马都必须入马厩.有两种颜色的马,如果 i 匹黑马与 j 匹白马同在一个马厩,不愉快系数是 i * j,总系数就是k个系数相加.让总系数最小. 思路 : dp[i][j] 代表的是前 i 个马厩放 j 匹马的最小不愉快系数值. 1 //1167 2 #include <cstdio> 3 #in

ural 1243. Divorce of the Seven Dwarfs

1243. Divorce of the Seven Dwarfs Time limit: 1.0 secondMemory limit: 64 MB After the Snow White with her bridegroom had left the house of the seven dwarfs, their peaceful and prosperous life has come to an end. Each dwarf blames others to be the rea

URAL 1297 Palindrome

Palindrome Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ID: 129764-bit integer IO format: %lld      Java class name: (Any) The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states

URAL - 1243 - Divorce of the Seven Dwarfs (大数取模)

1243. Divorce of the Seven Dwarfs Time limit: 1.0 second Memory limit: 64 MB After the Snow White with her bridegroom had left the house of the seven dwarfs, their peaceful and prosperous life has come to an end. Each dwarf blames others to be the re

HDU 3911 Black And White(线段树区间合并)

Problem Description There are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a magic brush, she can change the color of a continuous stone, black to white, white to black. Little Sheep like black very much, so she wan

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

ural 1272. Non-Yekaterinburg Subway

1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t