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. 中文情感分析 glove+LSTM

    最近尝试了一下中文的情感分析. 主要使用了Glove和LSTM.语料数据集采用的是中文酒店评价语料 1.首先是训练Glove,获得词向量(这里是用的300d).这一步使用的是jieba分词和中文维基. ...

  2. HDU 1228 字符串到数字的转化

    一道水题,练练字符串的输入输出 #include <cstdio> #include <cstring> using namespace std; ] , s2[]; int ...

  3. noip模拟赛 小Y的问题

    [问题描述]有个孩子叫小 Y,一天,小 Y 拿到了一个包含 n 个点和 n-1 条边的无向连通图, 图中的点用 1~n 的整数编号.小 Y 突发奇想,想要数出图中有多少个“Y 字形”.一个“Y 字形” ...

  4. 转载 - C++ - placement new

    出处:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 有关placement new                  ...

  5. [K/3Cloud]进度条控件编程接口

    进度条控件编程接口 1.启动进度查询 this.GetControl<ProgressBar>().Start(2)  //每2秒查询一次进度 2.汇报进度 在插件中重载 OnQueryP ...

  6. oracle 12c show con_name

    今天安装了一个oracle 12c的数据库做测试,在运行一个很简单的命令时出错了: SQL> show con_name concat "." (hex 2e) SP2: u ...

  7. OpenJudge百炼习题解答(C++)--题2704:竞赛评分

    题: 总时间限制:  1000ms  内存限制:  65536kB 描写叙述 现举行一次小竞赛,參赛的3支队伍,编号为1,2,3.每支队列轮流回答问题,假设回答正确,加10分;回答错误,扣10分;放弃 ...

  8. MYSQL利用Navicat对含有Bold字段表进行导入导出

    MYSQL中含有Blob字段是一件挺麻烦的事情,导出导入不方便.我介绍我是怎么做的. 1.在MYSQL的my.ini最后中加入一行配置max_allowed_packet = 100M,重新启动MYS ...

  9. JavaWeb开发环境搭建

    Tomcat 的主要配置 Tomcat:tomcat是实现了一个JavaEE标准的最小的Webserver,是Apche组织开发的,免费的server,能够在网络中直接下载. 最新的版本号应该是8的版 ...

  10. python练习-跳出多层循环和购物车

    跳出多层循环:三层循环,最里层直接跳出3层 在Python中,函数运行到return这一句就会停止,因此可以利用这一特性,将功能写成函数,终止多重循环 def work(): for i in ran ...