Hello 2019 B

Whiteying

2019-01-05 02:23:58

Personal

# 题目链接: https://codeforces.com/contest/1097/problem/B # 原题: **Problem Statement** Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: ![](https://codeforces.com/predownloaded/58/e2/58e2000e1b7dc1510062c974ea44c9e3188e72cd.png) Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be ai degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. **Input** The first line contains one integer n (1≤n≤15) — the number of rotations. Each of the following n lines contains one integer ai (1≤ai≤180) — the angle of the i-th rotation in degrees. **Output** If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). **Examples** **input1** 3 10 20 30 **output1** YES **input2** 3 10 10 10 **output2** NO **input3** 3 120 120 120 **output3** YES **Note** In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. ------------ # 题意: 你有一个360度量角器,初始指针在0度,给你一些数值,这些数值是指针的旋转度数,有可能是顺时针旋转也有可能是逆时针旋转,问你是否有一个方案使得指针转回0度。 # 思路: 数据规模特别小,因此一个个枚举旋转状态即可 # AC代码: ``` #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<set> typedef long long ll; #include<vector> #define cin(n) scanf("%lld",&(n)) #define cout(n) printf("%lld",(n)) #define couc(c) printf("%c",(c)) #define coutn printf("\n") #define cout_ printf(" ") #define debug() printf("haha\n") const int MAXN =10000005; ll t,n,k; ll a[MAXN]; ll ansa,ansb; ll MIN=0x3f3f3f3f; float fa,fb; double da,db,dc,dlat,dans; double dan[MAXN]; double eps=1e-6; char ch; int mpa[105][105]; int mpb[105][105]; std::string s[10],sb; bool flag; ll book[100]; void dfs(int now) { if(now==t+1) { ll ans=0; for(int i=1;i<=t;i++) { if(book[i]==1) ans+=a[i]; else ans-=a[i]; } if(ans%360==0) flag=1; return; } book[now]=1; dfs(now+1); book[now]=0; dfs(now+1); } int main() { cin(t); for(int i=1;i<=t;i++) { cin(a[i]); } dfs(1); if(flag) printf("YES\n"); else printf("NO\n"); return 0; } ```