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

inputoutput
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

转载于:https://www.cnblogs.com/StupidBoy/p/5241093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值