zoukankan      html  css  js  c++  java
  • 2013年山东省第四届ACM大学生程序设计竞赛 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
    这个题的话一开始挺没有思路的,后来看到题解是说 将p转换成一个二进制的数,然后分别乘上系数。
    一开始挺难理解的,T给我讲了,才明白了,其实可以在纸上自己先算算再自己写出二进制来,推一下,就可以理解了
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 using namespace std ;
     5 int main()
     6 {
     7     int n ;
     8     cin>>n ;
     9     while(n--)
    10     {
    11         int t ;
    12         int a[190],b[191] ;
    13         cin>>t ;
    14         memset(a,0,sizeof(a));
    15         for(int i = 0 ; i <= t-1 ; i++)
    16         {
    17             cin>>a[i];
    18         }
    19         int p;
    20         cin>>p;
    21         for(int i = 1 ; i <= p ; i++)
    22         {
    23             long long q ;
    24             cin>>q ;
    25             int x = 0;
    26             if(q == 0)
    27             {
    28                 cout<<"1"<<endl;
    29                 continue ;
    30             }
    31             while(q)
    32             {
    33                 b[x++] = q%2 ;
    34                 q = q/2 ;
    35             }
    36             int sum = 1 ;
    37             for(int j = 0 ; j <= x-1 ; j++)
    38             {
    39                 if(b[j])
    40                 {
    41                     sum = sum*a[j]%2012;
    42                 }
    43             }
    44             cout<<sum<<endl ;
    45         }
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    计算机网络 概述
    ISO/ISO 参考模型 和 TCP/IP模型
    Elasticsearch 6.2.3版本 执行聚合报错 Fielddata is disabled on text fields by default
    Elasticsearch 6.2.3版本 filtered 报错问题 no [query] registered for [filtered]
    Elasticsearch 6.2.3版本 Windows环境 简单操作
    MyBatis 模糊查询
    常用正则表达式
    页面加载时的div动画
    Highcharts的一些属性
    highcharts去掉x轴,y轴,轴线以及刻度
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3241937.html
Copyright © 2011-2022 走看看