B. Lost Number【CF交互题 暴力】
B. Lost Number【CF交互题 暴力】
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
inputCopy
16
64
345
672
outputCopy
? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42
Hint
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.
思路如下
这是第一次写CF交互题,虽然没有做出来,不过看完题解之后这题是真的简单。
- 题意:一个数组有 4 ,8 ,15,16,32,42 这6个数子组成,且每个元素在该数组中仅出现一次,让你通过4 提问,得出这个 数组各个位置的元素是什么并输出出来。(每次提问方式如下: 设 i , j 为所求数组的元素下标(i 与 j 可以相同),通过提问 i ,j 则系统会返回 i ,j 位置元素的乘积)
- 思路:固定提问位置 + 暴力枚举。
题解一(别人的)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const int inf = 1<<30;
const LL maxn = 1e5+10;
int main()
{
int n[6] = {4,8,15,16,23,42}, ans[6];
bool used[10];
int a, b, c, d;
ms(used, 0);
printf("? 1 2\n");
fflush(stdout);
scanf("%d",&a);
printf("? 2 3\n");
fflush(stdout);
scanf("%d",&b);
printf("? 3 4\n");
fflush(stdout);
scanf("%d",&c);
printf("? 4 5\n");
fflush(stdout);
scanf("%d",&d);
for(int i = 0; i < 6; ++i){
if(!used[i]){
used[i] = true;
for(int j = 0; j < 6; ++j){
if(!used[j]){
used[j] = true;
for(int k = 0; k < 6; ++k){
if(!used[k]){
used[k] = true;
for(int l = 0; l < 6; ++l){
if(!used[l]){
used[l] = true;
for(int p = 0; p < 6; ++p){
if(!used[p] && n[i]*n[j]==a&&n[j]*n[k]==b&&n[k]*n[l]==c&&n[l]*n[p]==d){
used[p] = true;
ans[0]=n[i], ans[1]=n[j], ans[2]=n[k], ans[3]=n[l], ans[4]=n[p];
int t = 0;
for(; t < 6; ++t)
if(!used[t]) break;
ans[5] = n[t];
i=j=k=l=p=9; break;
}
}
used[l] = false;
}
}
used[k] = false;
}
}
used[j] = false;
}
}
used[i] = false;
}
}
printf("! %d %d %d %d %d %d\n", ans[0], ans[1], ans[2], ans[3], ans[4], ans[5]);
return 0;
}
题解二(改编后的题解)
经题解一改编后
#include<iostream>
using namespace std;
int res[7];
int mark[7];
int map[7] = {4,8,15,16,23,42};
int ar[7];
//暴力搜索回溯
int flag = 0;
void dfs(int k,int last_val)
{
if(flag == 1)
return;
if(k == 5)
{
for(int i = 0; i < 6; i ++)
{
if(! mark[i])
{
res[k] = map[i];
flag = 1;
return;
}
}
}
for(int i = 0; i < 6; i ++)
{
if(k == 0 && !mark[i])
{
if(flag == 1)
return;
mark[i] = 1;
res[k] = map[i];
dfs(k + 1 , map[i]);
mark[i] = 0;
}
else if(k > 0 && !mark[i] && ar[k] == last_val * map[i])
{
if(flag == 1)
return;
mark[i] = 1;
res[k] = map[i];
dfs(k + 1 , map[i]);
mark[i] = 0;
}
}
}
int main()
{
//freopen("test.txt","r",stdin);
printf("? 1 2\n");
fflush(stdout);
scanf("%d",&ar[1]);
printf("? 2 3\n");
fflush(stdout);
scanf("%d",&ar[2]);
printf("? 3 4\n");
fflush(stdout);
scanf("%d",&ar[3]);
printf("? 4 5\n");
fflush(stdout);
scanf("%d",&ar[4]);
dfs(0 , 1);
printf("! %d %d %d %d %d %d\n", res[0], res[1], res[2], res[3], res[4], res[5]);
return 0;
}
B. Lost Number【CF交互题 暴力】的更多相关文章
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- CF1114E Arithmetic Progression(交互题,二分,随机算法)
既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #427 (Div. 2) E. The penguin's game (交互题,二进制分组)
E. The penguin's game time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- 交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]
交互题就是程序与电脑代码的交互. 比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数. 还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互 ...
- Codeforces 1137D - Cooperative Game - [交互题+思维题]
题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...
- Gym - 101375H MaratonIME gets candies 交互题
交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...
- 做了一道cf水题
被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
随机推荐
- python实验一
安徽工程大学 Python程序设计实验报告 班级物流管理191 姓名彭艺 学号3190505139成绩 日期 2020年3月3日 指导老师 修宇 实验名称 ...
- 【字节校招】【实习】【内推】字节跳动春招(校招或实习均可)以及日常实习内推ing
本人是年前刚刚入职抖音的应届生,职业认证还未来的级更改,但是这些都不重要.重要的是我们不能错过优秀的你~ 字节跳动的相关福利我就不介绍了,技术实习生是400/天,房补是1500/月,三餐免费,下午茶, ...
- LeetCode专题——详解搜索算法中的搜索策略和剪枝
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第20篇文章,今天讨论的是数字组合问题. 描述 给定一个int类型的候选集,和一个int类型的target,要求返 ...
- 曹工说mini-dubbo(1)--为了实践动态代理,我写了个简单的rpc框架
相关背景及资源: 之前本来一直在写spring源码解析这块,如下,aop部分刚好写完.以前零散看过一些文章,知道rpc调用基本就是使用动态代理,比如rmi,dubbo,feign调用等.自己也就想着试 ...
- 单元测试 - Tests和UITests (一) 业务测试
单元测试 假如我们今天去面试了,面试官问了一句“什么是单元测试?有没有使用?大概是针对那些情况进行单测的?单测意义从你实际使用中总结一下.” 这要在我没进行现在的单测之前这个问题我回答的可能就是“不好 ...
- 如何安装vue-devtool调试工具
1.从git上下载工具压缩包,github下载地址:https://github.com/vuejs/vue-devtools: 2.打开cmd,切换到下载的文件目录下:npm install---- ...
- 奇思妙想-java实现另类的pipeline模式
磕叨 在公司做项目是见到前辈们写的一端任务链的代码,大概如下 Runnable task = new TaskA(new TaskB(new TaskC(new taskD()))); task.ru ...
- RabbitMQ消息发布和消费的确认机制
前言 新公司项目使用的消息队列是RabbitMQ,之前其实没有在实际项目上用过RabbitMQ,所以对它的了解都谈不上入门.趁着周末休息的时间也猛补习了一波,写了两个窗体应用,一个消息发布端和消息消费 ...
- hackerone或PayPal转账到国内银行卡
1.首先hackerone会提示有W9那么一说,这个是美国人纳税的,我们是中国人不需要纳税的,只要给美国税务局发邮件说你是中国人不需要纳税就OK了.具体操作百度. 2.如此就会成功转账到你的PayPa ...
- Django CBV加装饰器、Django中间件、auth模块
一. CBV加装饰器 在视图层中,基于函数的视图叫FBV(function base views),基于类的视图叫CBV(class base views).当需要用到装饰器时,例如之前的基于Cook ...