CodeForces Gym 100685J Just Another Disney Problem (STL,排序)
题意:给定你大小未知的n个数,你允许有不超过一万次的询问,每次询问两个数,第i个数是否比第j个数小?然后后台会返回给你一个结果YES或者NO(即一行输入),
然后经过多次询问后,你需要给出一个正确的原未知序列的升序排列。
析:当时是真没看懂题意是啥意思,然后就放过了,如果看懂了,并不是很难么,这不就是一个排序么,你可以问后台要数据,然后你决定怎么排序,
我们只要处理这个排序就好,但是不能用sort进行排序,因为这个的复杂度并总不是nlogn,如果是极端数据就卡不过了,也就是说可能会超过询问10000次,
要么我们自己写个快排要么用stabble_sort,这个排序函数来解决。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];
string s; bool cmp(int a, int b){
cout << "1 " << a << " " << b << endl;
cin >> s;
return s[0] == 'Y';
} int main(){
cout.flush();
cin >> n;
for(int i = 0; i < n; ++i) a[i] = i+1;
stable_sort(a, a+n, cmp);
cout << "0";
for(int i = 0; i < n; ++i) cout << " " << a[i];
cout << endl;
return 0;
}
CodeForces Gym 100685J Just Another Disney Problem (STL,排序)的更多相关文章
- Codeforces Gym 100513D D. Data Center 前缀和 排序
D. Data Center Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560/proble ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- nginx源代码分析--配置信息的继承&合并
这里仅仅讲述http{}模块下的配置: 在ngx_http_block()函数内(这个函数别调用时在ngx_inti_cycle内的ngx_conf_parse函数,这个函数遇到http命令时 回调n ...
- Android中Environment与StatFs获取系统/SDCard存储空间大小
近期想起Android开发的知识.好久没有使用了,都忘得几乎相同了,今天查看了一会资料往回捡捡,顺便写下来帮助一下须要的同学. 首先讲述一下Environment与StatFs这两个类,然后介绍它们的 ...
- PHP获取IP
<?php $iipp = $_SERVER["REMOTE_ADDR"]; echo $iipp ; ?>
- Subversion基础:概念、安装、配置和基本操作(转)
本文转载至http://www.cnblogs.com/cokecoffe/archive/2012/06/01/2537130.html 转自:http://www.uml.org.cn/pzgl/ ...
- EasyDarwin开源流媒体服务器内存管理优化
-本文由EasyDarwin开源团队成员Fantasy贡献 前言 最近在linux上跑EasyDarwin发现一个很奇怪的问题,当有RTSPSession连接上来的时候,发现进程的虚拟内存映射一下就多 ...
- live555中fDurationInMicroseconds的计算
live555中fDurationInMicroseconds表示单个视频或者音频帧所占用的时间间隔,也表示在fDurationInMicroseconds微秒时间后再次向Source进行getNex ...
- openstack之路:KVM/Libvirt 安装
openstac是一个开源的计算机平台,利用虚拟化和底层存储服务提供云计算服务.openstack的基本是虚拟化技术.虚拟化技术采用的KVM.我们首先进行KVM软件的安装. 电脑配置: 内存:8G 硬 ...
- requirejs测试
参考资料:http://www.ruanyifeng.com/blog/2012/11/require_js.html 一.文件目录 二.html <!DOCTYPE html> < ...
- 封装class类为jar包提供给其他项目使用
一.完成class类的编写与测试工作 二.完善javadoc注释,生成自己的API 注释要按照标准要求进行 Project -- generate javadoc
- CISCO-端口安全
1.MAC地址与端口绑定,当发现主机的MAC地址与交换机上指定的MAC地址不同时 ,交换机相应的端口将down掉.当给端口指定MAC地址时,端口模式必须为access或者Trunk状况. 3550-1 ...