codeforces 1020 D The hat

71 篇文章 0 订阅
20 篇文章 0 订阅

D. The hat

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is an interactive problem.

Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered so that participant i and participant i + 1 (1 ≤ i ≤ n - 1) are adjacent, as well as participant n and participant 1. Each student was given a piece of paper with a number in such a way, that for every two adjacent students, these numbers differ exactly by one. The plan was to form students with the same numbers in a pair, but it turned out that not all numbers appeared exactly twice.

As you know, the most convenient is to explain the words to the partner when he is sitting exactly across you. Students with numbers i and  sit across each other. Imur is wondering if there are two people sitting across each other with the same numbers given. Help him to find such pair of people if it exists.

You can ask questions of form «which number was received by student i?», and the goal is to determine whether the desired pair exists in no more than 60 questions.

Input

At the beginning the even integer n (2 ≤ n ≤ 100 000) is given — the total number of students.

You are allowed to ask no more than 60 questions.

Output

To ask the question about the student i (1 ≤ i ≤ n), you should print «? i». Then from standard output you can read the number aireceived by student i ( - 109 ≤ ai ≤ 109).

When you find the desired pair, you should print «! i», where i is any student who belongs to the pair (1 ≤ i ≤ n). If you determined that such pair doesn't exist, you should output «! -1». In both cases you should immediately terminate the program.

The query that contains your answer is not counted towards the limit of 60 queries.

Please make sure to flush the standard output after each command. For example, in C++ use function fflush(stdout), in Java call System.out.flush(), in Pascal use flush(output) and stdout.flush() for Python language.

Hacking

Use the following format for hacking:

In the first line, print one even integer n (2 ≤ n ≤ 100 000) — the total number of students.

In the second line print n integers ai ( - 109 ≤ ai ≤ 109) separated by spaces, where ai is the number to give to i-th student. Any two adjacent elements, including n and 1, must differ by 1 or  - 1.

The hacked solution will not have direct access to the sequence ai.

Examples

input

Copy

8

2

2

output

Copy

? 4

? 8

! 4

input

Copy

6

1

2

3 

2

1

0

output

Copy

? 1

? 2

? 3

? 4

? 5

? 6

! -1

Note

Input-output in statements illustrates example interaction.

In the first sample the selected sequence is 1, 2, 1, 2, 3, 4, 3, 2

In the second sample the selection sequence is 1, 2, 3, 2, 1, 0.

 

交互题 题意问你给你一个圆圈的人啊 每个人都有数字卡片 问你有没有两个人卡片相同 输入一个数字 ?代表是第几个人拿这张卡片

我们可以构造函数f[x] -f[x+n/2] 发现他在1 到n/2具有连续单调性 那么就可以用二分啦

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
int n;
const int MAX_N = 100024;
long long f[MAX_N];
void in(int x){
    printf("? %d\n",x);
    fflush(stdout);
    int m,y;
    scanf("%d",&m);
    printf("? %d\n",x+n/2);
    fflush(stdout);
    scanf("%d",&y);
    f[x] = y - m;
}
int main(){
   scanf("%d",&n);
   in(1);
   int l = 1,r = n/2;
   if(f[1]==0) {
    printf("! 1\n");
    fflush(stdout);
    return 0;
   }
   while(l<=r){
    int mid = (l+r)>>1;
    in(mid);
    if(f[mid]==0) {
        printf("! %d\n",mid);
        fflush(stdout);
        return 0;
    }
    else if(f[mid]>0){
        if(f[1]>0){
            l = mid + 1;
        }
        else r = mid - 1;
    }
    else {
        if(f[1]>0){
            r = mid - 1;
        }
        else l = mid + 1;
    }
   }
   printf("! -1\n");
   fflush(stdout);
   return 0;
}

E抽空补题吧

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值