zoukankan      html  css  js  c++  java
  • SDUT 2608 Alice and Bob (巧妙的二进制)

    Alice and Bob

    Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

    题目描述

        Alice and Bob like playing games very much.Today, they introduce a new game.

        There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice ask Bob Q questions. In the expansion of the Polynomial, Given an integer P, please tell the coefficient of the x^P.

    Can you help Bob answer these questions?

    输入

    The first line of the input is a number T, which means the number of the test cases.

    For each case, the first line contains a number n, then n numbers a0, a1, .... an-1 followed in the next line. In the third line is a number Q, and then following Q numbers P.

    1 <= T <= 20

    1 <= n <= 50

    0 <= ai <= 100

    Q <= 1000

    0 <= P <= 1234567898765432

    输出

    For each question of each test case, please output the answer module 2012.

    示例输入

    1
    2
    2 1
    2
    3
    4

    示例输出

    2
    0

    提示

    The expansion of the (2*x^(2^0) + 1) * (1*x^(2^1) + 1) is 1 + 2*x^1 + 1*x^2 + 2*x^3

    来源

     2013年山东省第四届ACM大学生程序设计竞赛
     
     
    看到2,,自然想到二进制。。。
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int t,n,a[60];
        int q;
        long long p;
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                scanf("%d",&a[i]);
            scanf("%d",&q);
            while(q--){
                cin>>p;
                int loc;
                int ans=1,cnt=0;
                while(p){
                    loc=p&1;
                    //printf("%d",loc);
                    if(cnt>=n){
                        ans=0;
                        break;
                    }
                    if(loc==1)
                        ans=ans*a[cnt]%2012;
                    cnt++;
                    p>>=1;
                }
                printf("%d
    ",ans);
            }
        }
        return 0;
    }
  • 相关阅读:
    linux-01-04(创建文件夹mkdir,进入目录命令cd,创建文件命令 echo cp vim touch等,批量创建文件操作)
    linux-05(tar命令的使用)
    linux-06(移动命令mv)
    linux-07(复制命令cp)
    linux-08(查看命令历史记录history)
    cookie
    vue-router路由懒加载
    setTimeout async promise执行顺序总结
    forEach陷阱
    函数节流与函数防抖之间的区别
  • 原文地址:https://www.cnblogs.com/jackge/p/3147679.html
Copyright © 2011-2022 走看看