1167B. Lost Numbers

1167B. Lost Numbers

This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.

The jury guessed some array a consisting of 6 integers. There are 6 special numbers — 4, 8, 15, 16, 23, 42 — and each of these numbers occurs in a exactly once (so, a is some permutation of these numbers).

You don’t know anything about their order, but you are allowed to ask up to 4 queries. In each query, you may choose two indices i and j (1≤i,j≤6, i and j are not necessarily distinct), and you will get the value of ai⋅aj in return.

Can you guess the array a?

The array a is fixed beforehand in each test, the interaction program doesn’t try to adapt to your queries.

Interaction
Before submitting the answer, you may ask up to 4 queries. To ask a query, print one line in the following format: ? i j, where i and j should be two integers such that 1≤i,j≤6. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query — one line containing one integer ai⋅aj. If you submit an incorrect query (or ask more than 4 queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately — otherwise you may receive verdict “Runtime error”, “Time limit exceeded” or some other verdict instead of “Wrong answer”.

To give the answer, your program should print one line ! a1 a2 a3 a4 a5 a6 with a line break in the end. After that, it should flush the output and terminate gracefully.

Example
input
16
64
345
672
output
? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42
Note
If you want to submit a hack for this problem, your test should contain exactly six space-separated integers a1, a2, …, a6. Each of 6 special numbers should occur exactly once in the test. The test should be ended with a line break character.

问题概述:指定了随机顺序的4, 8, 15, 16, 23, 42数组,问其中4组两个数的乘积,说出数组的实际顺序

#include <iostream>
#include <math.h>
using namespace std;

int * fun(int n1,int n2)
{
	int arr[6]={4,8,15,16,23,42};//定义数组 
	static int temp[4];
	for (int i=0;i<6;i++)//遍历输入值是否是某两个数乘积 
	{
		for (int j=0;j<6;j++)
		{
			if (i!=j)
			{
				if(arr[i]*arr[j]==n1)//看n1是哪两个数相乘 
				{
					temp[0]=arr[i];
					temp[1]=arr[j];
				}
				if(arr[i]*arr[j]==n2)//看n2是哪两个数相乘 
				{
					temp[2]=arr[i];
					temp[3]=arr[j];
				}
			}
		}
	}
	if(temp[0]==temp[2])//共同的乘数就是a1,同时可以得到a2和a3 
	{
		temp[2]=temp[3];
	}
	if(temp[1]==temp[2])
	{
		int t;
		temp[2]=temp[3];
		t=temp[1];
		temp[1]=temp[0];
		temp[0]=t;
	}
	if(temp[1]==temp[3])
	{
		int t;
		t=temp[1];
		temp[1]=temp[0];
		temp[0]=t;
	}
	return temp;
}

int main(int argc, char** argv)
{
  int a[6],b[4],*p;
  cout<<"? "<<"1 "<<"2"<<endl;//应该问12,13,45,46从而得到所有数字 
  cin>>b[0];
  cout<<"? "<<"1 "<<"3"<<endl;
  cin>>b[1];
  p=fun(b[0],b[1]);//猜数函数 
  a[0]=p[0];
  a[1]=p[1];
  a[2]=p[2];
  cout<<"? "<<"4 "<<"5"<<endl;
  cin>>b[2];
  cout<<"? "<<"4 "<<"6"<<endl;
  cin>>b[3];
  p=fun(b[2],b[3]);
  a[3]=p[0];
  a[4]=p[1];
  a[5]=p[2];
  cout<<"! "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<endl;
  return 0;
}

遇到的问题:数组是固定的,可以考虑这个数组是否有某些特点,如任意两数相乘不能得到相同值。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值