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
Difficulty: 421
 
题意:有n个球,要么0,要么1,你先进行若干次操作,选择u,v,如果a[u]<a[v],那么他们交换
以上操作无任何反馈
最后进行一个论断:你选择两个你认为相等的位置输出
正确80%以上即可。
 
分析:首先我们可以都过交换操作来个冒泡之类的排序
然后随机选择两个相邻的点,正确率为(n-2)/(n-1)
总的正确率80%应该没问题。
 
 #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std; int n; int main()
{
ios::sync_with_stdio();
srand(time());
int m;
cin >> m;
for(int n = ; n <= m + ; n++)
{
for(int i = ; i <= n; i++)
for(int j = ; j < i; j++)
cout << "? " << j << ' ' << i << "\n";
int x = rand() % (n - ) + ;
cout << "! " << x << ' ' << x + << "\n";
cout.flush();
}
return ;
}

ural 2063. Black and White的更多相关文章

  1. 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 wit ...

  2. ural 1221. Malevich Strikes Back!

    1221. Malevich Strikes Back! Time limit: 1.0 secondMemory limit: 64 MB After the greatest success of ...

  3. URAL 1297 Palindrome 后缀数组

    D - Palindrome Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  4. URAL 1297 最长回文子串(后缀数组)

    1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...

  5. 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 wi ...

  6. Ural 1225. Flags 斐波那契DP

    1225. Flags Time limit: 1.0 secondMemory limit: 64 MB On the Day of the Flag of Russia a shop-owner ...

  7. imshow() displays a white image for a grey image

    Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 ...

  8. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  9. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

随机推荐

  1. NPOI基本操作XLS

    using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...

  2. 困难的串(dfs)

    困难的串 题意: 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的串”.例如,                 BB.ABCDABCD都是容易的串,而D.DC.ABDAD ...

  3. iPhone:4.7 5.5 4 3.5 对应的各个设备屏幕尺寸对应的像素及App上线信息

    Shared App Information You can access these properties from the App Details page in the App Informat ...

  4. hdu 2057 A+B

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057 For each test case,print the sum of A and B in h ...

  5. Jmeter 中使用非GUI启动进行压力测试

    使用非 GUI 模式,即命令行模式运行 JMeter 测试脚本能够大大缩减所需要的系统资源.使用命令jmeter -n -t <testplan filename> -l <list ...

  6. MVC – 5.MVC设计模式和.NetMVC框架

    MVC模式-设计模式 •控制器(Controller)- 负责转发请求,对请求进行处理. •视图 (View) - 界面设计人员进行图形界面设计. •模型 (Model)-业务逻辑.数据.验证规则.数 ...

  7. Netty网络编程之NIO概览与简单应用

    >>关于NIO Java NIO即Java Non-blocking IO(Java非阻塞I/O),是Jdk1.4之后增加的一套操作I/O工具包,又被叫做Java New IO. (1)R ...

  8. Session 类

     Session 类 Session 类可以使用户在浏览您的网站时,维持他们的状态并跟踪他们的行为. Session 类将每个用户的 session 信息序列化(serialize)后存储到到 coo ...

  9. web开发的步骤

    前端知道是浏览器呈现的部分,相对于前端,后台你可以理解为服务器端专门处理.读取.存储数据库数据的部分. 因为网站是基于B\S架构,即浏览器---服务端架构,就程序来讲,可笼统划分为前端程序和服务器端程 ...

  10. 监听报错 TNS-00525: Insufficient privilege for operation 11gR2 + 连接报错ORA-12537: TNS:connection closed

    1.TNS-00525: Insufficient privilege for operation Started with pid= Listening on: (DESCRIPTION=(ADDR ...