CodeForces Round#313

第一题想当然了,结果被坑。。

有1的肯定能构成所有的其他数,没有1的肯定构不成1 ,这题T T

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
      int n, arr;
      int tag = 0;
      scanf("%d", &n);
      for(int i = 0; i < n; ++i) {
            scanf("%d", &arr);
            tag = (arr == 1 || tag == 1) ? 1 : 0;
      }
      if(tag) cout << -1 << endl;
      else cout << 1 << endl;
      return 0;
}

第二题,就是考虑的边界有点多。

#include<bits/stdc++.h>
using namespace std;
int main() {
      int b[2];
      int p1[2], p2[2];
      cin >> b[0] >> b[1] >> p1[0] >> p1[1] >> p2[0] >> p2[1];
      sort(b, b+2); sort(p1, p1+2); sort(p2, p2+2);
      if((p1[0] * p1[1] + p2[0] * p2[1]) > (b[0] * b[1]) || p2[1] > b[1] || p1[1] > b[1] ) {
            cout << "NO" << endl;
      } else {
            int tag = 0;
            int x[4];
            x[0] = b[0] - p1[0];
            x[2] = b[1] - p1[1];
            x[1] = b[0] - p1[1];
            x[3] = b[1] - p1[0];

            if(p2[0] <= min(x[0], b[1]) && p2[1] <= max(x[0], b[1]))
                  tag = 1; //cout << 1 << endl;
            else if (p2[0] <= min(x[2], b[0]) && p2[1] <= max(x[2], b[0]))
                   tag = 1; //cout << 2 << endl;
            else if(p2[0] <= min(x[1], b[1]) && p2[1] <= max(x[1], b[1]))
                   tag = 1; //cout << 3 << endl;
            else if(p2[0] <= min(x[3], b[0]) && p2[1] <= max(x[3], b[0]))
                   tag = 1; //cout << 4 << endl; cout << x[3] << b[1] << endl;
            if(tag)
                  cout << "YES" << endl;
            else
                  cout << "NO" << endl;
      }
      return 0;
}

第三题,就是算个等角六边形的面积,可以补成大矩形算,也可以补成大正三角形算。用分割的方法反而复杂许多,而且还遇到精度丢失问题

#include <bits/stdc++.h>
using namespace std;

int main() {
      int a[6];
      for(int i = 0; i < 6; ++i)
            cin >> a[i];
      cout << (a[0] + a[1] + a[2])*(a[0] + a[1] + a[2])-a[0] * a[0] - a[2] * a[2] - a[4] * a[4] << endl;
      return 0;
}
原文地址:https://www.cnblogs.com/ya-cpp/p/4677520.html