• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

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          

       
                                                                                                                                                                                                                                                                                                                                                    
                Class:                               LittleElephantAndDouble              
                Method:                               getAnswer              
                Parameters:                               vector <int>              
                Returns:                               string              
                Method signature:                               string getAnswer(vector <int> A)              
                (be sure your method is public)              
       
                      
                 
         

            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}
                   
             
               
Returns: "YES"
             
                                                                                       
                      One possible way of making all elements equal is to                       double the element at index 0.                    
             
       
          1)                          
                                                                                                                                                            
                                                                                       
                     
{1, 2, 3}
                   
             
               
Returns: "NO"
             
                                                                                       
                      It's impossible to make all three elements equal in this                       case.                    
             
       
          2)                          
                                                                                                                                                            
                                                                                       
                     
{4, 8, 2, 1, 16}
                   
             
               
Returns: "YES"
             
                                                                                       
                                         
             
       
          3)                          
                                                                                                                                                            
                                                                                       
                     
{94, 752, 94, 376, 1504}
                   
             
               
Returns: "YES"
             
                                                                                       
                                         
             
       
          4)                          
                                                                                                                                                            
                                                                                       
                     
{148, 298, 1184}
                   
             
               
Returns: "NO"
             
                                                                                       
                                         
             
       
          5)                          
                                                                                                                                                            
                                                                                       
                     
{7, 7, 7, 7}
                   
             
               
Returns: "YES"
             
                                                                                       
                                         
             
       

   

      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 };
View Code

 

posted @ 2013-11-21 19:29  HaibaraAi  阅读(112)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3