SRM 597 DIV2 250
2013-11-21 10:34
267 查看
Problem Statement | ||||||||||||
Little Elephant from the Zoo of Lviv likes integers. You are given an vector <int> A. On a single turn, Little Elephant can double (i.e., multiply by 2) any element of A. He may double the same element more than once, if he wants to. He wants to obtain an array in which all elements are equal. Return "YES" (quotes for clarity) if it is possible to do that and "NO" otherwise. | ||||||||||||
Definition | ||||||||||||
| ||||||||||||
Notes | ||||||||||||
- | The return value is case-sensitive. Make sure that you return the exact strings "YES" and "NO". | |||||||||||
Constraints | ||||||||||||
- | A will contain between 1 and 50 elements, inclusive. | |||||||||||
- | Each element of A will be between 1 and 1,000,000,000, inclusive. | |||||||||||
Examples | ||||||||||||
0) | ||||||||||||
| ||||||||||||
1) | ||||||||||||
| ||||||||||||
2) | ||||||||||||
| ||||||||||||
3) | ||||||||||||
| ||||||||||||
4) | ||||||||||||
| ||||||||||||
5) | ||||||||||||
|
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class LittleElephantAndDouble {
public:
string getAnswer(vector <int>);
};
bool ck(int x)
{
int lb=x&(-x);
return x==lb;
}
string LittleElephantAndDouble::getAnswer(vector <int> A) {
int Max=-999999,t=A.size();
bool flag=true;
string Yes("YES"),No("NO");
for(int i=0;i<t;i++) Max=max(Max,A[i]);
for(int i=0;i<t;i++)
{
if(A[i]==Max) continue;
if(Max%A[i]!=0) {flag=false;break;}
if(ck(Max/A[i])==false) {flag=false;break;}
}
if(flag) return Yes;
else return No;
}
//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
相关文章推荐
- SRM 599 div2 250 500
- 【topcoder SRM 702 DIV 2 250】TestTaking
- TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%
- SRM 670 DIV 2 Cdgame 250-point
- SRM 604 DIV2 250
- TopCoder 250 points 13-SRM 150 DIV 1 82.63/250 33.05%
- TopCoder 250 points 19-SRM 153 DIV 1 84.72/250 33.89%
- tc-SRM-626-DIV1-250
- tc-SRM-626-DIV1-250
- Topcoder SRM 661 (Div.1) 250 MissingLCM - 数论
- TopCoder SRM 612 DIV1 250 EmoticonsDiv1
- TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
- TopCoder 250 points 20-SRM 153 DIV 2 216.58/250 86.63%
- TopCoder 300 points 24-SRM 155 DIV 2 75/250 30%
- TopCoder 250 points 4-SRM 145 DIV 2 128.72/250 51.49%
- topcoder srm 610 div2 250
- 记第一次TopCoder, 练习SRM 583 div2 250
- Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索
- TopCoder算法竞赛题1:SRM 144 DIV 2, 250-point
- TopCoder算法竞赛题5:SRM 149 DIV 2, 250-point