http://codeforces.com/problemset/problem/730/B

题意:一个交互式问题,给出一个n代表有n个数字,你可以问下标为x和y的数的大小,会给出">","<"或"=",要求询问次数不能超过 ,最后输出最小的数和最大的数的下标。

思路:很新奇的题目。先将两两比较整理出一个max数组和min数组,这个时候前后较大的一个会在max数组中,较小的会在min数组中,这个时候询问了n/2次。接着我们只要对每个组进行比较,因为较大的已经在max数组里面了,我们只要递推求得较大的,同理,也可以递推求得较小的。最后的答案就是最后的组了。

记得每次printf之后要fflush(stdout)。

 #include <bits/stdc++.h>
using namespace std;
int ma[], mi[]; int main() {
int t;
scanf("%d", &t);
while(t--) {
int n;
scanf("%d", &n);
char s[]; int cnt = ;
for(int i = ; i < n; i += , cnt++) {
printf("? %d %d\n", i, i + );
fflush(stdout);
scanf("%s", s);
if(s[] == '>') ma[cnt] = i, mi[cnt] = i + ;
else ma[cnt] = i + , mi[cnt] = i;
}
if(n & ) { ma[cnt] = n, mi[cnt] = n; cnt++; }
for(int i = ; i < cnt; i++) {
printf("? %d %d\n", ma[i-], ma[i]);
fflush(stdout);
scanf("%s", s);
if(s[] == '>') ma[i] = ma[i-];
printf("? %d %d\n", mi[i-], mi[i]);
fflush(stdout);
scanf("%s", s);
if(s[] == '<') mi[i] = mi[i-];
}
printf("! %d %d\n", mi[cnt-], ma[cnt-]);
fflush(stdout);
}
return ;
}

Codeforces 730B:Minimum and Maximum(交互式问题)的更多相关文章

  1. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】

    B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes ...

  3. Codeforces 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈

    Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...

  4. Qt 的几个核心机制总结之 布局(QWidget可以设置setSizePolicy,而QSizePolicy有Fixed,minimum,maximum,preferred,expanding,ignore等7个属性,还可以横竖分开)

    1.Qt布局的作用 Qt的布局是通过布局管理器来实现的,布局管理器负责在父类窗口部件区域构建子窗口部件,使得放置在窗体中的每个窗口部件都有一个适合的大小和位置,并且能够随着应用程序本身的变化而变化从而 ...

  5. codeforces 496A. Minimum Difficulty 解题报告

    题目链接:http://codeforces.com/contest/496/problem/A 题目意思:给出有 n 个数的序列,然后通过删除除了第一个数和最后一个数的任意一个位置的数,求出删除这个 ...

  6. Codeforces 1092F Tree with Maximum Cost(树形DP)

    题目链接:Tree with Maximum Cost 题意:给定一棵树,树上每个顶点都有属性值ai,树的边权为1,求$\sum\limits_{i = 1}^{n} dist(i, v) \cdot ...

  7. [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]

    咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...

  8. Codeforces 1154G Minimum Possible LCM

    题目链接:http://codeforces.com/problemset/problem/1154/G 题目大意: 给定n个数,在这些数中选2个数,使这两个数的最小公倍数最小,输出这两个数的下标(如 ...

  9. Codeforces 1107G Vasya and Maximum Profit [单调栈]

    洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的 ...

随机推荐

  1. WPF中实现PropertyGrid(用于展示对象的详细信息)的三种方式

    原文:WPF中实现PropertyGrid(用于展示对象的详细信息)的三种方式 由于WPF中没有提供PropertyGrid控件,有些业务需要此类的控件.这篇文章介绍在WPF中实现PropertyGr ...

  2. thinkphp 删除所有缓存 Rumtime 以及 Html 静态缓存

    <?php /** * This is not a free software, All Copyright @F.Z.B * Date: 14-8-12 下午4:08 * File: Cach ...

  3. QT实现鼠标钩子(使用SetWindowsHookEx安装mouseProc函数)

    HHOOK mouseHook=NULL; LRESULT CALLBACK mouseProc(int nCode,WPARAM wParam,LPARAM lParam ) { if(nCode ...

  4. 【C#】WixToolset快速入门教程

    原文:[C#]WixToolset快速入门教程 介绍 给windows系统做软件,常见的打包工具大家可能都听说过,如:大名鼎鼎的Installshield.Inno setup等.在遇见Wix之前In ...

  5. aspx页面@Page指令解析

    @Page指令位于每个ASP.NET页面的顶部,告诉ASP.NET这个具体页面使用什么属性,以及该页面继承的用户控件.ASP.NET页面@Page指令属性有:AspCompat.Async.Async ...

  6. iOS 自定义UIButton

    工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求 首先写个自定义的button CustomButton.h #import <UIKi ...

  7. Win10《芒果TV》春季商店版更新v3.3.0:全新视觉蜕变&支持快男直播

    在微软发布Win10创意者更新正式版前夕,Win10版<芒果TV>迅速更新至v3.3.0,主要是全新升级视觉交互,新增大咖快男个人直播,全面优化底层架构,启动大提速. Win10版< ...

  8. Qt 5.9对Mac的图形显示有许多改进

    We have some platform specific improvements as well as support for new platforms and compilers comin ...

  9. WPF实现系统禁音的方法

    方法1: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern ...

  10. 自定义View相关的博客收藏

    颜色: http://android.jobbole.com/83283/ 坐标: http://android.jobbole.com/83276/ 流程介绍: http://android.job ...