zoukankan      html  css  js  c++  java
  • CodeForces679A

    CodeForces679A
    也是交互题,这个要稍微难一些.
    考虑的过程大概是:
    (1)肯定没有问的价值,如果问过(2),那么除了(4)之外的偶数都不用问了.
    要问(4)的原因是,如果这个数字是(4),那就会被误判为(prime).
    然后,质数是要问的,最后判断问出来的数字中约数是否大于等于(2)个,是的话就是合数,否则就是偶数.
    但这样会在完全平方数的时候出错,因为它们可能会有一对质数相乘得到,然后就冇了.所以我们就再判断一下完全平方数.
    需要注意的是,只询问小于等于(50)的完全平方数和质数就行了,完全平方数也不用全都去问,不全问的原理和问了(2)就不用问大于(4)的偶数一样.
    (Code:)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
    #define per(i,a,b) for (int i = a ; i >= b ; -- i)
    #define pii pair < int , int >
    #define X first
    #define Y second
    #define rint read<int>
    #define int long long
    #define pb push_back
    
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    using std::swap ;
    using std::sort ;
    using std::unique ;
    using std::greater ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
           while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
       return f * x ;
    }
    
    template < class T >
        inline void write (T x) {
           static T stk[100] , top = 0 ;
           if ( x == 0 ) { putchar ('0') ; return ; }
           if ( x < 0 ) { x = - x ; putchar ( '-' ) ; }
           while ( x ) { stk[++top] = x % 10 ; x /= 10 ; }
           while ( top ) { putchar ( stk[top--] + '0' ) ; }
           putchar ('
    ') ;
        }
    
    int p[55] , cnt , d[] = { 0 , 4 , 9 , 25 , 49 } , tot ;
    char ans[5] ;
    
    inline bool check (int x) {
        if ( x == 1 ) return false ;
        for (int i = 2 ; i * i <= x ; ++ i)
            if ( x % i == 0 ) return false ;
        return true ;
    }
    
    signed main (int argc , char * argv[]) {
        rep ( i , 1 , 50 ) if ( check ( i ) ) p[++cnt] = i ;
        rep ( i , 1 , cnt ) {
            printf ("%lld
    " , p[i] ) ; fflush ( stdout ) ;
            scanf ("%s" , ans ) ; if ( ans[0] == 'y' ) ++ tot ;
        }
        rep ( i , 1 , 4 ) {
            printf ("%lld
    " , d[i] ) ; fflush ( stdout ) ;
            scanf ("%s" , ans ) ; if ( ans[0] == 'y' ) ++ tot ;
        }
        puts ( tot < 2 ? "prime" : "composite" ) ;
        system ("pause") ; return 0 ;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    js幻灯片效果!
    构造函数和析构函数的简单说明
    ASP.NET接口的基础使用例子
    带预览图的js切换效果!
    在win7系统中安装sqlserver2005出现 [Microsoft][SQL Native Client]客户端不支持加密问题!
    Win7开启无线共享上网的方法
    C# 结构体 简明介绍
    C#访问修饰符简单说明
    C#不定长参数的使用
    研究了一下Google Ajax Search API, 给博客做了个样品
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11470908.html
Copyright © 2011-2022 走看看