codeforces 679A Bear and Prime 100 交互

第一次交互题,记录一下吧

#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e3+5;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int prime[55];
bool vis[55];
char s[5];
int main()
{
   for(int i=2;i<=50;++i)
    if(!vis[i])
    for(int j=i*i;j<=50;j+=i)
       vis[j]=1;
   int cnt=0;
   for(int i=2;i<=50;++i)
    if(!vis[i])prime[++cnt]=i;
   int ret=0,x;
   for(int i=2;i<=cnt;++i){
     printf("%d\n",prime[i]);
     fflush(stdout);
     scanf("%s",s);
     if(s[0]==‘y‘)++ret,x=prime[i];
   }
   if(ret>=2){
     printf("composite\n");
     fflush(stdout);
   }
   else if(ret==1){
      printf("2\n");
      fflush(stdout);
      scanf("%s",s);
      if(s[0]==‘y‘){
        printf("composite\n");
        fflush(stdout);
      }
      bool flag=0;
      for(int i=x*x;i<=100;i*=x){
        printf("%d\n",i);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]==‘y‘){
          flag=1;
          break;
        }
      }
      if(flag)printf("composite\n");
      else printf("prime\n");
      fflush(stdout);
   }
   else{
     int x=-1;
     for(int i=2;i<=100;i*=2){
        printf("%d\n",i);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]==‘y‘){
          x=i;
        }
     }
     if(x==-1||x==2)printf("prime\n");
     else printf("composite\n");
      fflush(stdout);
   }
   return 0;
}

时间: 2024-12-14 09:56:41

codeforces 679A Bear and Prime 100 交互的相关文章

Codeforces A - Bear and Prime 100(交互题)

A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数. #include<bits/stdc++.h> using namespace std; #define ll long long

Codeforces 385C Bear and Prime Numbers(素数预处理)

Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时

暑假练习赛 006 B Bear and Prime 100

Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 680C uDebug Description Input Output Sample Input Sample Output Hint Description

codeforces679A_Bear and Prime 100 交互题

传送门 第一道交互题 题意: 电脑事先想好了一个数[2,100] 你会每次问电脑一个数是否是它想的那个数的因数 电脑会告诉你yes或no 至多询问20次 最后要输出它想的数是质数还是合数 思路: 枚举<50的质数和4,9,25,49即可判断 4,9, 25,49单独看作质数是这样方便判断2^2,3^2,...,9^2 解释: 在使用多个输出函数连续进行多次输出时,有可能发现输出错误. 因为下一个数据再上一个数据还没输出完毕,还在输出缓冲区中时,下一个printf就把另一个数据加入输出缓冲区, 结

CodeForces 385C Bear and Prime Numbers 素数打表

第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample has 3 queries. The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9. The second query comes

codeforces 385C Bear and Prime Numbers

题意:给你一个数列,和m个询问,求 数组种 l -r 中所有质数的的倍数的个数和. 解题思路:变形筛法.注意细节 解题代码: 1 // File Name: 385c.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月07日 星期六 18时24分53秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #in

Codeforces 385C Bear and Prime Numbers [素数筛法]

Code: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<string> #include<queue> #include<deque> #include<stack> #include<map&g

Codeforces 385B Bear and Strings

题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAX_N = 5000 + 100; char str[MAX_N]; struct Node

Codeforces.835E.The penguin&#39;s game(交互 按位统计 二分)

题目链接 \(Description\) 有一个长为\(n\)的序列,其中有两个元素为\(y\),其余全为\(x\).你可以进行\(19\)次询问,每次询问你给出一个下标集合,交互库会返回这些元素的异或和.给定\(n,x,y\),你需要求出两个\(y\)的下标. \(n\leq 1000,1\leq x,y\leq 10^9\). \(Solution\) 对连续区间询问得到的结果只有那么几种,可以直接判断\(y\)的个数的奇偶性.但是区分不出来该区间有0个还是2个\(y\). 两个\(y\)的