2022河南联赛第(二)场:河南理工大学 ---复盘

A 妙手 — 打表推导

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
const int N = 200010 , mod = 1e18;
signed main()
{
	int a, b; cin >> a >> b;
    if(((a + b) & 1 ) && __gcd(a, b) == 1) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

B 宝石 — map优化

#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define int long long
const int N = 2010;
int a[N];
signed main()
{
    int n; cin >> n;
    for(int i = 0; i < n; i ++) cin >> a[i];
    unordered_map<int,int>mp;

    for(int i = 0; i < n; i ++)
        for(int j = i; j < n; j ++)
            mp[a[i] * a[j]] = i;
    
    int res = 0;
    for(int i = 0; i < n; i ++)
        for(int j = i + 1; j < n; j ++)
            if(!a[j] && !a[i] || a[j] && a[i] % a[j] == 0 && mp[a[i] / a[j]] > i)
            {
                res ++;
                break;
            }

    cout << res << '\n';
}

C 斩龙 — 模拟

#include<iostream>
using namespace std;
#define int long long
signed main()
{
    int a1, a2, a3, h1, h2, h3, k, x;
    cin >> a1 >> h1 >> a2 >> h2 >> x;
    cin >> k >> a3 >> h3;
    
    int res = 0;
    int sum = x - k;
    int cnt2 = (h2 + a1 - 1) / a1;
    if(sum > 0)
    {
        res += cnt2 * sum;
        h1 -= (cnt2 - 1) * sum * a2;
    }
    
    k = min(x, k);
    res += cnt2 * k;
    h1 -= a3 * cnt2 * k;
    h1 -= a2 * (cnt2 - 1) * k;
    
    int cnt1 = (h3 + a1 - 1) / a1;
    res += cnt1;
    h1 -= (cnt1 - 1) * a3;
    
    if(h1 < 0) cout << "No Franxx!\n";
    else cout << res << '\n';
    
}

D 数对 ---- 树状数组 + 推导

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
const int N = 400010;

int n, x, y;
int tr[N], s[N];
vector<int> nums;

int find(int x)
{
    return lower_bound(nums.begin(), nums.end(),x) - nums.begin() + 1;
}
int lowbit(int x)
{
    return x & -x;
}

void add(int x, int v)
{
    for(int i = x; i <= 2 * n + 2; i += lowbit(i)) tr[i] += v; 
}

int query(int x)
{
    int res = 0;
    for(int i = x; i; i -= lowbit(i)) res += tr[i];
    return res;
}

signed main()
{
    cin >> n >> x >> y; 
    for(int i = 1; i <= n; i ++)
    {
        cin >> s[i];
        s[i] -= y;
        s[i] += s[i - 1];
    }
    for(int i = 0; i <= n; i ++)
    {
        nums.push_back(s[i]);
        nums.push_back(s[i] - x - 1);
    }
    
    sort(nums.begin(),nums.end());
    nums.erase(unique(nums.begin(), nums.end()), nums.end());
    
    int res = 0;
    for(int i = 0; i <= n; i ++)
    {
        res += query(2 * n + 2) - query(find(s[i] - x - 1));
        add(find(s[i]), 1);
    }
    cout << res << '\n';
}

E 双星 — 数学

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define int long long

const double pi = acos(-1);

struct circle {
    int x, y, r;
    double a, b;

    void input() { cin >> x >> y >> r; }
    void cal_ab(){ // 计算圆所占的极角序区间 [a, b]
        double mid = atan2(y, x), rad = asin(r / sqrt(x * x + y * y));
        a = mid - rad, b = mid + rad;
    }
};

bool check_intersected(double a, double b, double c, double d){
	// 判断两个区间 [a, b], [c, d] 是否有交集
	return c < b && a < d;
}

bool check_seeable(double a, double b, double c, double d){
	// 判断 [c, d] 在 [a, b] 的遮挡下是否能被看到;是返回 1,否则返回 0
    return c < a || d > b;
}

circle c1, c2;

signed main()
{
    c1.input(), c2.input();
    c1.cal_ab(), c2.cal_ab();
    if(c1.x * c1.x + c1.y * c1.y > c2.x * c2.x + c2.y * c2.y)
    	swap(c1, c2); // 靠近原点的圆作为 c1
    	
    for(double dt : {0.0, -2 * pi, 2 * pi}){
    	double a = c1.a, b = c1.b, c = c2.a + dt, d = c2.b + dt;
    	
		if(check_intersected(a, b, c, d)){
    		if(check_seeable(a, b, c, d)) cout << "Yes";
    		else cout << "No";
    		return 0;
    	}
    }
    
    cout << "Yes";

}

F 手办 — 签到

#include<iostream>
#include<vector>
using namespace std;
#define int long long
signed main()
{
    vector<int>vec;
    for(int i = 1; i <= 1000; i ++) vec.push_back(i*i*i);
    
    int T; cin >> T;
    while(T --)
    {
        int n; cin >> n;
        int res = 0;
        for(int i = 1; i <= 1000; i ++)
            if(n % vec[i - 1] == 0) res ++;
        cout << res << '\n';
    }
}

G 无限 — dp

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
const int N = 2000010 , mod = 998244353;
int f[N];
signed main()
{
    int n; cin >> n;
	f[1] = 1;
    for(int i = 2; i <= n; i ++) f[i] = (f[i - 1] + f[i - 2]) % mod;
    int res = 0;
    for(int i = 1; i <= n; i ++) res = (res + f[i]) % mod;
    cout << res << '\n';
}

H 0和1 — 贪心

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
const int N = 200010 , mod = 1e18;

string s;
int cal(char op)
{
    vector<pair<int,int> > vec;
    int res = 0;
    for(int i = 0; i < s.size(); i ++)
    {
        if(s[i] == op)
        {
            int j = i;
            while(s[j] == s[i]) j ++;
            j --;
            if(vec.size() && j - i + 1 + vec.back().second - vec.back().first + 1 >= 3 && vec.back().second + 2 == i)
            {
                res ++;
                vec.back().second = j;
            }
            else vec.push_back({i, j});
            i = j;
        }
    }
    
    for(auto [l, r] : vec)
        if(r - l + 1 >= 2) res += 2;
        else res ++;
    return res;
}

signed main()
{
	cin >> s;
    cout << min(cal('0'), cal('1')) << '\n';
}

I 22数 — 数位dp / dfs暴搜

数位dp
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
const int N = 200010 , mod = 1e18;
int n;
int f[11][11][110];
// 前 i 位 第 i 位为 j,数字之和 为 k的 数的个数
// f[i][j][k] += f[i - 1][u][k - j];

void init()
{
    for(int i = 0; i <= 9; i ++) f[1][i][i] = 1;
    for(int i = 2; i <= 10; i ++)
        for(int j = 0; j <= 9; j ++)
            for(int k = j; k <= 90; k ++)
                for(int u = 0; u <= 9; u ++)
                    f[i][j][k] += f[i - 1][u][k - j];
}

int cal(int n)
{
    
    vector<int> nums;
    while(n) nums.push_back(n % 10), n /= 10;
    int res = 0, sum = 0, len = nums.size();
    for(int i = nums.size() - 1; i >= 0; i --)
    {
        int x = nums[i];
        for(int j = i == nums.size() - 1; j < x; j ++)
            res += f[i + 1][j][len * 2 - sum];
        sum += x;
        if(sum > len * 2) break;
        if(!i && sum == len * 2) res ++;
    }
    
    for(int i = 1; i < len; i ++)
        for(int j = 1; j <= 9; j ++)
            res += f[i][j][2 * i];   
    return res;
}

signed main()
{
    init();
	cin >> n;
    cout << cal(n) << '\n';
}
暴搜
#include<iostream>
using namespace std;
#define int long long
int n, res = 0;
void dfs(int x, int sum, int cnt)
{
    if(x > n || sum > 20) return ;
    if(cnt && sum == cnt * 2) res ++;
    for(int i = 0; i <= 9; i ++)
    {
        int y = x * 10 + i;
        if(y) dfs(y, sum + i, cnt + 1);
    }
}
signed main()
{
    cin >> n;
    dfs(0,0,0);
    cout << res << '\n';
}

J 签到 — 签到

#include<iostream>
#include<set>
using namespace std;
#define int long long
const int N = 1010;
int a[N];
signed main()
{
    int n; cin >> n;
    for(int i = 0; i < n; i ++) cin >> a[i];
    set<int> S;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            S.insert(a[i] + a[j]);
    
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            if(S.count(a[i] - a[j]))
            {
                cout << "Yes" << '\n';
                return 0;
            }
    cout << "No" << '\n';
}

K 大米 — 线段树

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
const int N = 200010 , mod = 1e18;
int n, m;
int w[N];
struct node
{
    int l, r;
    int os, es;
    int tag;
}tr[N << 2];

void pushup(node &u, node &l, node &r)
{
    u.os = l.os + r.os;
    u.es = l.es + r.es;
}

void pushup(int u)
{
    pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}

void pushtag(int u)
{
    int tmp = tr[u].es;
    tr[u].es = tr[u].os * 2;
    tr[u].os = tmp / 2;
    tr[u].tag ^= 1;
}

void pushdown(int u)
{
    if(tr[u].tag)
    {
        pushtag(u << 1);
        pushtag(u << 1 | 1);
        tr[u].tag = 0;
    }
}

void build(int u, int l, int r)
{
    tr[u] = {l, r};
    if(l == r)
    {
        tr[u].os = w[l];
        return ;
    }
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    pushup(u);
    
}

void modify(int u, int l, int r)
{
    if(tr[u].l >= l && tr[u].r <= r)
        return pushtag(u);
    int mid = tr[u].l + tr[u].r >> 1;
    pushdown(u);
    if(l <= mid) modify(u << 1, l, r);
    if(r > mid) modify(u << 1 | 1, l, r);
    pushup(u);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) cin >> w[i];
    build(1, 1, n);
    while(m --)
    {
        int l, r; cin >> l >> r;
        modify(1, l, r);
        cout << tr[1].os + tr[1].es << '\n';
    }
}

L HPU — 签到

#include<iostream>
#include<cstring>
using namespace std;
signed main()
{
    string s; cin >> s;
    int res = 0;
    if(s.size() < 3)
    {
        cout << 0 << '\n';
        return 0;
    }
    for(int i = 0; i + 2 < s.size(); i ++)
        if(s[i] == 'H' && s[i + 1] == 'P' && s[i + 2] == 'U') res ++;
    cout << res << '\n';
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_WAWA鱼_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值