交互题

ABC244 C - Yamanote Line Game

题目链接
https://atcoder.jp/contests/abc244/tasks/abc244_c

解析
感觉这个交互题的要求相对明确,而且就只是加了一句fflush(stdout),不知道是不是典型交互。
image
写的时候wa了一发是因为忘记break了,还是代码能力不够强。

Ac代码

点击查看代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2010;

int n;
bool st[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n + 1;i ++){
        for(int j = 1; j <= 2 * n + 1; j ++){
            if(!st[j]){
                printf("%d\n", j);
                fflush(stdout);
                st[j] = true;
                break;
            }
        }
        int x;
        scanf("%d", &x);
        if(x == 0) return 0;
        else st[x] = true;
    }
    return 0;
}

posted @   小菜珠的成长之路  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示