AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 其它
    • 题解
    • 分享
    • 商店
    • 问答
  • 吐槽
  • 登录/注册

[记录笔记[牛3]]

作者: 作者的头像   莫德歪奇 ,  2023-01-25 17:48:47 ,  所有人可见 ,  阅读 33


0


新知识,常写错的关于二分闭区间
1.左闭右闭,这种写法是左闭右开常常遗漏的答案的纠正
左闭右开每次更新左端点都是l==r时取到,此时可能会遗漏右端点能取到的答案
A

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[100010];
int main()
{
    cin >> n;
    ll res = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        while (a[i] > 0 && a[i] % 2 == 0)a[i] /= 2;
        res += (ll)a[i];
    }
    cout << res << endl;
    return 0;
}

D

1.偶数总有奇数的因子
2.奇数只能有奇数的因子
3.1为奇数
所以三点得出先手偶数为胜者
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    cin >> n;
    if (n % 2ll == 0)puts("kou");
    else
        puts("yukari");
    return 0;
}

C

n=4k,7和<4特判
#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int x;
    if(n<4||n==7)
    {
        cout<<-1;
        return 0;
    }else if(n%4==0)
    {
        cout<<"3 4 1 2 ";
        x=4;
    }else if(n%4==1)
    {
        cout<<"3 4 5 1 2 ";
        x=5;
    }else if(n%4==2)
    {
        cout<<"4 5 6 1 2 3 ";
        x=6;
    }else if(n%4==3)
    {
        cout<<"4 5 6 1 2 3 10 11 7 8 9 ";
        x=11;
    }
    while(x<n)
    {
        printf("%d %d %d %d ",x+3,x+4,x+1,x+2);
        x+=4;
    }

    return 0;
}

B
QQ截图20230125192743.png

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 2e5 + 10;
int a[maxx], m, t;
ll mx, n;
inline ll get_num(ll x)
{
    if (x <= mx)return x;
    return x + x - mx + x - mx;
}
int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%lld", &n);
        mx = (n + 1) >> 1;//上取整
        if (n == 2)
        {
            puts("-1");
            continue;
        }
        ll l = 1, r = n, res = n;
        while (l <= r)
        {
            ll mid = (l + r) >> 1;
            if (get_num(mid) <= n)l = mid + 1, res = mid;
            else r = mid - 1;
        }
        printf("%lld\n", res);
    }
    return 0;
}

E

高中数学
其实可以直接向量倒退点的坐标,需要手计算
但是答案直接三角形全等,根据长度直接算的点的坐标
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
    int xa,xb,ya,yb;
    cin>>xa>>ya>>xb>>yb;
    int nx=xa-xb;
    int ny=ya-yb;
    int xx=ny;
    int yy=-nx;
    if ((nx+xx)%2==0 && (ny+yy)%2==0)
    {
        cout<<xb+(nx+xx)/2<<' '<<yb+(ny+yy)/2;
    }else
    {
        puts("No Answer!");
    }
}

0 评论

你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息