码迷,mamicode.com
首页 > 编程语言 > 详细

CodeForces Gym 100685J Just Another Disney Problem (STL,排序)

时间:2016-09-01 22:40:13      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

题意:给定你大小未知的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,排序)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5831417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!