Div2 Medium: DivisibleSetDiv2

Problem Statement

     You are given a vector <int> b containing a sequence of n positive integers: b[0], ..., b[n-1]. We are now looking for another sequence a[0], ..., a[n-1]. This sequence should have the following properties:

  • Each a[i] should be a number of the form 2^x[i] where x[i] is some positive integer. In other words, each a[i] is one of the numbers 2, 4, 8, 16, ...
  • For each i, the value a[i]^b[i] (that is, a[i] to the power b[i]) should be divisible by P, where P is the product of all a[i].

Determine whether there is at least one sequence with the desired properties. Return "Possible" (quotes for clarity) if such a sequence exists and "Impossible" otherwise.

Definition

    
Class: DivisibleSetDiv2
Method: isPossible
Parameters: vector <int>
Returns: string
Method signature: string isPossible(vector <int> b)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 256
Stack limit (MB): 256

Constraints

- b will contain between 1 and 50 elements, inclusive.
- Each element in b will be between 1 and 10, inclusive.

Examples

0)  
    
{3,2}
Returns: "Possible"
One valid sequence is the sequence {2, 2}. That is, a[0] = a[1] = 2. Clearly, each a[i] is a power of two not smaller than 2. The product of all a[i] is 2*2 = 4. Both a[0]^b[0] = 2^3 = 8 and a[1]^b[1] = 2^2 = 4 are divisible by 4.
1)  
    
{3,3,3}
Returns: "Possible"
Here, one valid sequence is {2, 2, 2}.
2)  
    
{1,10}
Returns: "Impossible"
Suppose that a[0] = x and a[1] = y. The value a[0]^b[0] = x^1 should be divisible by x*y. This is only possible for y = 1. However, 1 is not a positive power of two, so we cannot have a[1] = 1.
3)  
    
{2, 3, 10}
Returns: "Possible"
One valid sequence is {8, 4, 2}.
4)  
    
{7,10,4,6,3}
Returns: "Possible"
 
5)  
    
{9,9,9,9,9,9,9,9,9}
Returns: "Possible"
 
6)  
    
{3,4,5,6,7}
Returns: "Impossible"
 

  This is a mathematical problem which is very simple to implement but hard to prove. It turns out that the answer is "Possible" if and only if ∑i=0n−11bi≤1∑i=0n-11bi≤1. You can find a detailed proof below.

  We are asked if there exists a sequence of powers of two (a0,a1,...,an−1)(a0,a1,...,an-1) that for every i:

  Finally, we should avoid losing accuracy in order to use the perfect formula. Casuing the range of bi is [1, 10], we can multiply a constant C which equal to LCM(1,...,10).

public string isPossible(vector<int> b) {
int LCM = , sum = ;
for (int bi : b)
sum += LCM / bi; // sum up 1/b multiplied by LCM to avoid floats
return (sum <= LCM) ? "Possible" : "Impossible";
}

  Recently, I had met two mathematical problems. The last one is hihoCoder_5 using log to get the maximum value.

____+++++____

  

SRM-697-DIV2的更多相关文章

  1. SRM 657 DIV2

    -------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...

  2. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  3. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  4. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  5. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  6. SRM 638 Div2

    2333... 因为TC过少的参与者.加上不断fst 我掉了div2该. 幸运的是完成的背div1该.. 250 水的问题 500 水的问题.. 直接bfs扩展即可了 注意判重.  我还用康托展开了真 ...

  7. SRM 592 DIV2 报告

    昨天下午查看邮箱,看到了topcoder的SRM比赛通知和cf的比赛通知,当时什么也不想做,心里空荡荡的,忽然就想参加一下,试试看.吃完晚饭回来一看,就剩十几分钟了,匆忙把平台下了,就开始等待比赛开始 ...

  8. SRM 670 div2 A B C div1 A(贪心,子问题合并)

    A Cdgame brute force... B Drbalance 贪心,每次选最前面的-变成+,相当于后面所有的负值+2. C Treestrat 考虑集中去抓一个Red Token,以这个To ...

  9. topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)

    A题,熊孩子测视力,水题,题意就是判断一下两个数对应位不相同的数字有多少个. #include<bits/stdc++.h> using namespace std; class Bear ...

  10. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

随机推荐

  1. Ubuntu挂载硬盘,修改卷标

    Ubuntu挂载硬盘,修改卷标转载2016-03-06 17:03:21标签:ubuntu Ubuntu不像windows,硬盘插入电脑不会自动读取硬盘 数据,需要把硬盘挂载到文件夹上,然后才能访问硬 ...

  2. mongodb数据库的一些常用命令列表

    超级用户相关:use admin #增加或修改用户密码db.addUser(ixigua,'pwd') #查看用户列表db.system.users.find() #用户认证db.auth(ixigu ...

  3. hdu 1874 dijkstra 队列实现 比数组高效特别在稀疏图

    参考  http://blog.csdn.net/zhuyingqingfen/article/details/6370561 刘汝佳白皮书 #include<stdio.h> #incl ...

  4. 洛谷——P1720 月落乌啼算钱

    题目背景 (本道题目木有以藏歌曲……不用猜了……) <爱与愁的故事第一弹·heartache>最终章. 吃完pizza,月落乌啼知道超出自己的预算了.为了不在爱与愁大神面前献丑,只好还是硬 ...

  5. [bzoj1821][JSOI2010]部落划分(贪心)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1821 分析:题目看起来很吊,但只要贪心就行了,每次取相邻最近的两个点所在的集合合并知道 ...

  6. bridge 上网

    手头有一台机器上有一个虚拟机 虚拟机为桥接 本机为静态IP上网 想让虚拟机上网的方式是 本机不设ip 网卡设置DHCP. 虚拟机设置静态ip

  7. windows 2008 64位在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配

    在本机32位环境中使用access数据库正常. 公布到server上时提示:在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配 server是64位环境.windows 2008,64位的t ...

  8. python requests使用

    参考:http://cn.python-requests.org/zh_CN/latest/ 1.使用requests发送请求: >>> r = requests.get('http ...

  9. A Taxonomy for Performance

    A Taxonomy for Performance In this section, we introduce some basic performance metrics. These provi ...

  10. Oracle 简单的列转行

    需求是,统计每一个部门不同工种的薪水总和. SQL> select deptno,ename,job,sal from emp;     DEPTNO ENAME      JOB       ...