zoukankan      html  css  js  c++  java
  • CF1064 E

    题意

    交互题, 本来应该是在平面上进行的.
    实际上换成一条直线就可以, 其实换成在平面上更复杂一些.

    Solution

    假设(l)点是黑点, (r)处是白点, 那么就把下一个点的位置放置在(l + r / 2)处, 然后递归处理.

    Code

    #include <ctype.h>
    #include <stdio.h>
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int N = 39;
    
    struct Node {
    	int color, position;
    	bool operator < (const Node &x) const {
    		return color == x.color ? position < x.position : color < x.color;
    	}
    } p[N];
    const int XXX = 4323;
    
    bool Check(int position, int now) {
    	string s;
    	p[now].position = position;
    	printf("%d %d
    ", XXX, position);
    	fflush(stdout);
    	cin >> s;
    	if (s == "white") return p[now].color = 0;
    	else return p[now].color = 1;
    }
    
    int main() {
    	int n;
    	scanf("%d", &n);
    	int l = 1, r = 1e9, mid;
    	for (int i = 1; i <= n; i += 1) {
    		mid = l + r >> 1;
    		if (Check(mid, i)) r = mid;
    		else l = mid;
    	}
    	int res = 0;
    	for (int i = 1; i < n; i += 1)
    		std:: swap(p[i], p[i + 1]);
    	std::sort(p + 1, p + 1 + n);
    	for (int i = 2; i <= n; i += 1)
    		if (p[i].color != p[i - 1].color) {
    			res = p[i - 1].position + 1;
    			break;  
    		}  
    	if (res) printf("%d %d %d %d
    ", XXX - 1, res - 1, XXX + 1, res), fflush(stdout);
    	else printf("%d %d %d %d
    ", XXX - 1, res, XXX + 1, res), fflush(stdout);
    
    	return 0;
    }
    
  • 相关阅读:
    mySQL练习题
    JAVA实现C/S结构小程序
    JavaLinkedHashSet练习
    关于Extjs删除分页后删除最后一条数据页面无效的问题。
    hibernate 插入,更新数据库错误
    错误!错误!错误!
    坑爹的oracle
    关于hibernate实体类
    第一个项目的需求分析
    Ueditor 单独使用上传图片及上传附件方法
  • 原文地址:https://www.cnblogs.com/qdscwyy/p/9800439.html
Copyright © 2011-2022 走看看