Topcoder SRM 597 div2 A
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) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 #include <set> 5 #include <cstring> 6 #include <string> 7 #include <map> 8 #include <cmath> 9 #include <ctime> 10 #include <algorithm> 11 #include <queue> 12 13 using namespace std; 14 #define INF 0x7fffffff 15 #define maxm 1001 16 #define mp make_pair 17 #define pb push_back 18 #define rep(i,n) for(int i = 0; i < (n); i++) 19 #define re return 20 #define fi first 21 #define se second 22 #define sz(x) ((int) (x).size()) 23 #define all(x) (x).begin(), (x).end() 24 #define sqr(x) ((x) * (x)) 25 #define sqrt(x) sqrt(abs(x)) 26 #define y0 y3487465 27 #define y1 y8687969 28 #define fill(x,y) memset(x,y,sizeof(x)) 29 30 typedef vector<int> vi; 31 typedef long long ll; 32 typedef long double ld; 33 typedef double D; 34 typedef pair<int, int> ii; 35 typedef vector<ii> vii; 36 typedef vector<string> vs; 37 typedef vector<vi> vvi; 38 39 template<class T> T abs(T x) { re x > 0 ? x : -x; } 40 41 const int maxn = 10005; 42 43 int n, m, t, s, k, x; 44 //string s; 45 vector<int>A; 46 class LittleElephantAndDouble{ 47 public: 48 string getAnswer(vector<int> &A){ 49 if (A.size() == 1)return "YES"; 50 int ma = -INF; 51 int flag = A[0]; 52 for (int i = 1; i < A.size(); i++){ 53 if (A[i] * flag < 0)flag = -2; 54 if (flag == -2)return "NO"; 55 for (int i = 0; i < A.size(); i++)A[i] = abs(A[i]); 56 for (int i = 0; i < A.size(); i++) 57 if (A[i]>ma)ma = A[i]; 58 int t = 0; 59 for (int i = 0; i < A.size(); i++) 60 if (ma == 0 && A[i] == 0 || A[i] != 0 && ma%A[i] == 0 && (ma / A[i]) % 2 == 0 || ma == A[i])t++; 61 if (t == A.size())return "YES"; 62 else return "NO"; 63 } 64 } 65 };
浙公网安备 33010602011771号