#Codeforces Round 1009

#Codeforces Round 1009

##A - Draw a Square

CodeForces - 2074A 

我们只需要判断L==R,D==U,以及,R==D即可。

#include
using namespace std;
​
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int l,r,d,u;
        cin>>l>>r>>d>>u;
        if(l==r&&d==u&&l==d&&r==u) cout<<"Yes"< 
  

##B - The Third Side

https://vjudge.net/problem/CodeForces-2074B/origin

因为求的是最大元素我们考虑三角不等式

x+y>z即x+y>=z+1

每次取出两个数变为这两个数和加一,所以最后剩下的数就是这些数的和S-(n-1).

#include
using namespace std;
typedef long long LL;
 
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n;
       cin>>n;
       LL res=0;
       for(int i=1;i<=n;i++) 
       {
           int x;
           cin>>x;
           res+=x;
       }
       res=res-(n-1);
       cout< 
  

##C - XOR and Triangle

https://vjudge.net/problem/CodeForces-2074C/origin

#include 
#define int long long
using namespace std;
/*
直接让y尽可能的二进制每一位填满1。
又y x?
找个极限情况,x各位也为1
11111
 1111
10000
这种情况下 z + y = x, 这样的x是无解的。
​
所以答案是肯定的,当x某一位为0时,z会得1加上y的会发生进位,此时>x;
                x某一位为1时,z会得0,加y会得1,此时=x。
*/
// y  = 2^k + 1 < x -> k < log2(x - 1)
// 111111
void solve(){
    int x;
    cin >> x;
    for(int k = 0; k < log2(x-1); k++){
      int y = pow(2,k) + 1;
      if( (y + x > (x ^ y)) && ((x ^ y) > y - x) && (x ^ y) + y > x ){
        cout << y << endl;
        return;
      }
    }
    cout << -1 << endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);  
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

代码一致给出一些补充说明

x 100110010100

y 000000100000

z

由于抑或具有自反性所以yz是对称的 不妨设y

全部为0的话x+y=z,所以必有这一位后面的某一位x位1它也为1造成进位才可以,当y的这一位为1

x的这一位为0时情况对称。所以我们要在x的除了首位的第一个0/1y变成1/0,在这一位的后面x的第

一个1/0y变成0/1.

综合来看只有1会造成影响因为^又称不进位加法只有1会造成进位,顾我们考虑y全为1的情况即可出于

简便考虑

##D - Counting Points

https://vjudge.net/problem/CodeForces-2074D/origin

由于x的范围过大显然不能从x的角度出发,我们从c和这个圆与x轴的交点考虑这个x对应的y有多少点位于

圆内即可,然后看看这个坐标下的每个圆取最大值即可吗,特别注意浮点数有精度问题需要特判一下,eg:

如果变为4.999下取整完就变4了其实我们需要的是5

#include
using namespace std;
typedef long long LL;
​
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        int n,m;
        scanf("%d%d",&n,&m);
        vector cen(n);  // 改为long long
        vector rad(n);
        
        for(int i=0;i ans;  // key改为long long
        
        for(int i=0;i 
  

##G - Game With Triangles: Season 2

https://vjudge.net/problem/CodeForces-2074G/origin

没什么多说的区间dp和这个很像,就是加了一维选不选这3个点,而且不能选边界点,不能重复

选,且最优解中不一定所有点都会被选

找不到页面 - AcWing

#include
using namespace std;
typedef long long LL;
const int N=404;
int w[N];
LL f[N][N];
​
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        memset(f,0,sizeof f);
        for(int i=0;i 
  

注意初始化边界一些细节问题即可

你可能感兴趣的:(算法)