CF#512 Div2

A.In Search of an Easy Problem

 

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 const int N=110;
 5 int n; int a[N];
 6 bool judge() {
 7     for (int i=1;i<=n;i++)
 8         if (a[i])
 9             return true;
10     return false;
11 }
12 int main() {
13     scanf("%d",&n);
14     for (int i=1;i<=n;i++)
15         scanf("%d",&a[i]);
16     if (judge()) printf("HARD\n");
17     else printf("EASY\n");
18     return 0;
19 }
View Code

 

B.Vasya and Corfield

 

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int n,d,m;
 5 bool check(int x,int l,int r) {
 6     return x>=l&&x<=r;
 7 }
 8 int main() {
 9     scanf("%d%d%d",&n,&d,&m);
10     for (int x,y,i=1;i<=m;i++) {
11         scanf("%d%d",&x,&y);
12         if (check(y-x,-d,d)&&check(x+y,d,2*n-d))
13             printf("YES\n");
14         else
15             printf("NO\n");
16     }
17     return 0;
18 }
View Code

 

C.Vasya and Golden Ticket

注意细节……

 

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 const int N=110;
 5 int n;
 6 int a[N];
 7 char str[N];
 8 bool judge(int len) {
 9     int sum=0,st=len+1;
10     for (int i=1;i<=len;i++)
11         sum+=a[i];
12     while(st<=n) {
13         int tot=a[st++];
14         while(st<=n&&tot<sum) tot+=a[st++];
15         while(st<=n&&!a[st]) st++;
16         if (tot!=sum) return false;
17     }
18     return true;
19 }
20 int main() {
21     scanf("%d",&n);
22     scanf("%s",str);
23     for (int i=0;i<n;i++)
24         a[i+1]=str[i]-'0';
25     for (int len=1;len<n;len++)
26         if (judge(len)) {
27             printf("YES\n");
28             return 0;
29         }
30     printf("NO\n");
31     return 0;
32 }
View Code

 

D.Vasya and Triangle

题意:构造一个指定面积的三角形,要求在$x\in[0,n],y\in[0,m]$,三角形面积为$\frac{nm}{k},k\in[2,10^{9}]$

做法:可以证明一定可以构造出一个紧贴坐标系的直角三角形满足条件,否则无解。

 

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 ll n,m,k;
 6 ll gcd(ll a,ll b) {
 7     if (!b) return a;
 8     return gcd(b,a%b);
 9 }
10 int main() {
11     scanf("%I64d%I64d%I64d",&n,&m,&k);
12     ll res=n*m*2;
13     if (res%k) printf("NO\n");
14     else {
15         ll t1=gcd(n,k);
16         ll a=n/t1;
17         k/=t1;
18         ll t2=gcd(m,k);
19         ll b=m/t2;
20         k/=t2;
21         if (k==1) {
22             if (a*2<=n) a*=2;
23             else b*=2;
24         }
25         printf("YES\n");
26         printf("0 0\n");
27         printf("%I64d 0\n",a);
28         printf("0 %I64d\n",b);
29     }
30     return 0;
31 }
View Code

 

posted @ 2018-10-02 07:44  2018szb  阅读(91)  评论(0)    收藏  举报