zoukankan      html  css  js  c++  java
  • Gym 100792C Colder-Hotter (三分)

    题意:系统有一个点对,让你去猜,每次你猜一个,如果这个数和系统里的那个点距离比上一个你猜的近,那么返回1,否则返回0,第一次猜一定返回0,在不超过500次的情况下,猜出正确答案。

    析:是一个简单的三分,横纵坐标可以分开来考虑,每次两次三分,然后看那个点更偏向哪边即可,注意这个题,有一个坑,那就是你输出的点不能超过1e9,即使是在运算过程中也不行,也就是说上界必须是  1e9,其他的都不对,我就写了1e9+1,WA到死。。。。

    代码如下:

    #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>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define FOR(x,n)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    #define pii pair<int, int>
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<LL, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e18;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 18260 + 100;
    const LL mod = 1000000007;
    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 bool is_in(int r, int c) {
      return r > 0 && r <= n && c > 0 && c <= m;
    }
    
    
    int main(){
      int ansx = 0, ansy = 1e9;
      int cnt = 0, x1, x2;
      int idx = 0;
      while(ansx < ansy){
        int m1 = ansx + (ansy - ansx) / 3;
        int m2 = ansy - (ansy - ansx) / 3;
        cout << 0 << " " << m1 << endl << endl;
        cout.flush();
        cin >> x1;
    
        cout << 0 << " " << m2 << endl << endl;
        cout.flush();
        cin >> x2;
        if(x2 == 1)  ansx = m1 + 1;
        else ansy = m2 - 1;
        cnt += 2;
        if(cnt > 500)  assert(0);
      }
      int ansxx = ansx;
      ansx = 0, ansy = 1e9;
      idx = 0;
      while(ansx < ansy){
        int m1 = ansx + (ansy - ansx) / 3;
        int m2 = ansy - (ansy - ansx) / 3;
        cout << m1 << " " << ansxx << endl << endl;
        cout.flush();
        cin >> x1;
    
        cout << m2 << " " << ansxx << endl << endl;
        cout.flush();
        cin >> x2;
        if(x2 == 1)  ansx = m1 + 1;
        else ansy = m2 - 1;
        cnt += 2;
        if(cnt > 500)  assert(0);
      }
      cout << "A " << ansx << " " << ansxx << endl;
      return 0;
    }
    

      

  • 相关阅读:
    vi编辑器常用配置
    vi编辑器使用
    Windows进程通信 -- 共享内存
    Loadrunner关于页面检查的几个函数详解
    使用Loadrunner进行文件的上传和下载
    LR学习笔记之—参数和变量
    LoadRunner字符串处理
    在LoadRunner中查找和替换字符串
    为LoadRunner写一个lr_save_float函数
    LoadRunner中调用SHA1算法加密字符串
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7572784.html
Copyright © 2011-2022 走看看