省赛13 Alice and Bob(组合数学,)

题意:多项式相乘,(a0x+1)(a1x^2+1)(a2x^4+1),问x的m次方的系数是多少,当时没做出来,搜的某大神的博客,好理解。

思路:多列几个式子就能明白规律了:

(a0x+1)(a1x^2+1)(a2x^4+1)

=a0a1a2x^7+a1a2x^6+a0a2x^5+a2x^4+a0a1x^3+a1x^2+a0x+1

列出来后发现正好该数化为二进制,如果为1,则相乘

7:a0a1a2   即1+2+4

6:a1a2      即2+4

5:a0a2      即1+4

4:a2         即4

3:a0a1     即1+2

2:a1        即2

1:a0        即1

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 using namespace std;
 5
 6 #define maxn 105
 7
 8 int a[maxn],pos[maxn];
 9
10 int main()
11 {
12     int t,n,i,j,q,ans;
13     long long p;//因为0 <= p <= 1234567898765432
14     scanf("%d",&t);
15     while(t--)
16     {
17         scanf("%d",&n);
18         memset(a,0,sizeof(a));//这个很妙,比如n=3,则p>=8以后都要=0,就靠这一句
19         for(i=0;i<n;i++)
20         {
21             scanf("%d",&a[i]);
22         }
23         scanf("%d",&q);
24         while(q--)
25         {
26             scanf("%lld",&p);
27             if(p==0)
28             {
29                 printf("1\n");//别忘了
30                 continue;
31             }
32             memset(pos,0,sizeof(pos));
33             i=0;
34             while(p)
35             {
36                 pos[i++]=p%2;//求p转化为二进制
37                 p/=2;
38             }
39             ans=1;
40             for(j=0;j<i;j++)
41             {
42                 if(pos[j])//如果那一位二进制=1
43                 {
44                     ans=ans*a[j]%2012;//则就是那几位相乘,一边乘一遍取余2012
45                 }
46             }
47              printf("%d\n",ans);
48         }
49     }
50     return 0;
51 }

时间: 2025-01-19 22:08:04

省赛13 Alice and Bob(组合数学,)的相关文章

[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

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

题目地址: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)*....

ACdream群赛1112(Alice and Bob)

题意:http://acdream.info/problem?pid=1112 Problem Description Here  is Alice and Bob again ! Alice and Bob are playing a game. There are several numbers.First, Alice choose a number n.Then he can replace n (n > 1)with one of its positive factor but not

codeforces_346A Alice and Bob(数学)

题目链接:http://codeforces.com/problemset/problem/346/A 参考链接:http://blog.csdn.net/loy_184548/article/details/50174615 感受到数学在博弈论中的强大. 考虑最后终止状态的序列-无法取出任意两个数他们的差值不存在这个序列中:那么这必定是个首项等于公差的等差序列 而这个序列是 d 2d 3d....,因此可以通过a[1] a[2] a[3] ...的最大公约数得到 然后计算有几个数没在数组中,判

博弈问题-Alice与Bob拿牌游戏

Description Bob and Alice play a game, and Bob will play first. Here is the rule of the game: 1) There are N stones at first; 2) Bob and Alice take turns to remove stones. Each time, they can remove p^k stones. p is prime number, such as 2, 3, 5, ...

ZOJ 3666 Alice and Bob (SG博弈)

题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 题意: 给一个有向图,然后A和B轮流移动棋子,棋子在每一个位置可以重叠,当某人不能走时,输! 问A和B谁赢 方法: 显然每一局游戏都是独立的,对每一局游戏异或即可 每一局游戏的结果可以用SG求,记忆化搜索之 1 int dfs(int x) 2 { 3 if (sg[x] != -1) return sg[x]; 4 bool vis[maxn]; 5 me

【HDOJ】3660 Alice and Bob&#39;s Trip

就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. 1 import java.lang.*; 2 import java.io.*; 3 import java.util.*; 4 5 6 public class Main { 7 8 public static void main(String[] args) throws java.lang.Exception { 9 InputStream inputSt

XTU1168:Alice and Bob(二维DP)

摘要:Dota(Defence of the Ancients,远古的守护), 是指基于魔兽争霸3:冰封王座(暴雪娱乐公司出品)的多人即时对战自定义地图,可支持10个人同时连线游戏.Dota以对立的两个小队展开对战,通常是5v5,游戏目的是守护自己的远古遗迹(近卫方的生命之树.天灾方的冰封王座),同时摧毁对方的远古遗迹.DotA是目前唯一被暴雪娱乐公司官方认可的魔兽争霸RPG.Dota在大学生中的风靡程度令人咂舌,而随着玩家对游戏的理解深入,本身存在于游戏中的许多数学模型被挖掘出来进行研究.游戏

hdu 4268 Alice and Bob

Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 1 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Alice and Bob's game nev