首页 > 其他分享 >牛客周赛 Round 49

牛客周赛 Round 49

时间:2024-06-30 23:53:21浏览次数:10  
标签:std 49 int long 牛客 solve using Round define

A题

按题目输出即可

#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define lowbit(x) (x) & (-x)
using i64 = long long;
using pii = std::pair<int, int>;
void solve()
{
    i64 a, b;
    std::cin >> a >> b;
    std::cout << (a - b) - b * 10;
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

B题

二进制位数相当于某个数可以分解的次数

#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define lowbit(x) (x) & (-x)
using i64 = long long;
using pii = std::pair<int, int>;
void solve()
{
    int h;
    std::cin >> h;
    int cnt = 0;
    int x = h;
    while (x) {
    	x /= 2;
    	cnt ++;
    }
    int ans = 1;
    int res = 0;
    while (cnt --) {
    	res += ans;
    	ans *= 2;
    }
    std::cout << res << '\n';
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

C题

当一段的结果小于0时,就重新开始一段

#include<bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define lowbit(x) (x) & (-x)
using i64 = long long;
using pii = std::pair<int, int>;
void solve()
{
    int n, x;
    std::cin >> n >> x;
    std::vector<int> a(n);
    for (int i = 0; i < n; i ++) {
    	std::cin >> a[i];
    	a[i] -= x;
    }
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < n; i ++) {
    	sum += a[i];
    	if (sum < 0) {
    		sum = 0;
    	}
    	ans = std::max(ans, sum);
    }
    std::cout << ans << '\n';
}
signed main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

D题

根据前缀异或和的思想,可以得到答案是s[r] ^ s[l - 1]
根据打表
x % 4 == 0时,1到x的异或和是x
x % 4 == 1时,1到x的异或和是1
x % 4 == 2时,1到x的异或和是x + 1
x % 4 == 3时,1到x的异或和是0

#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define lowbit(x) (x) & (-x)
using i64 = long long;
using pii = std::pair<int, int>;
void solve()
{
	i64 l, r;
	std::cin >> l >> r;
	auto calc = [&](i64 x) -> i64 {
		if (x % 4 == 0) {
			return x;
		}
		else if (x % 4 == 1) {
			return 1;
		}
		else if (x % 4 == 2) {
			return x + 1;
		}
		else {
			return 0;
		}
	};
	std::cout << (calc(r) ^ calc(l - 1)) << '\n';
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    std::cin >> T;
    while (T --) solve();
    return 0;
}

E题

将第一个式子的y,带入第二个式子
可以求得a1 * b2 * x^2 + (b1 * b2 + a2) * x + (c1 * b2 + c2) = 0
然后分类讨论一下答案即可

import math
t = int(input())
def solve():
	a1, b1, c1, a2, b2, c2 = list(map(int, input().split()))
	a = a1 * b2
	b = b1 * b2 + a2
	c = c1 * b2 + c2
	detla = b * b - 4 * a * c
	if (a == 0):
		if (b == 0):
			if (c == 0):
				print("INF")
			else:
				print(0)
		else:
			print(1)
	else:
		if detla < 0: 
			print(0)
		elif detla == 0:
			print(1)
		else:
			print(2)
for _ in range(0, t):
	solve()

F题

字符串哈希
h[1 ~ n - 2 * k] + h[2 * k + 1, n] == 2 * h[k + 1, n - k]

#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define lowbit(x) (x) & (-x)
using i64 = long long;
using pii = std::pair<int, int>;
using u64 = unsigned long long;
bool isprime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int findPrime(int n) {
    while (!isprime(n)) {
        n++;
    }
    return n;
}
void solve()
{
    std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    const int P = findPrime(rng() % 900000000 + 100000000);
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i ++) {
        std::cin >> a[i];
    }
    std::vector<u64> p(n + 1), h(n + 1);
    p[0] = 1;
    for (int i = 0; i < n; i ++) {
        p[i + 1] = p[i] * P;
        h[i + 1] = h[i] * P + a[i];
    } 
    auto find = [&](int l, int r) -> u64{
        return h[r] - h[l - 1] * p[r - l + 1];
    };
    for (int k = 1; k <= n; k ++) {
        if (find(1, n - 2 * k) + find(2 * k + 1, n) == 2 * find(k + 1, n - k)) {
            std::cout << k << '\n';
            return;
        }
    }
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

标签:std,49,int,long,牛客,solve,using,Round,define
From: https://www.cnblogs.com/KXDdesu/p/18277198

相关文章

  • 《Programming from the Ground Up》阅读笔记:p1-p18
    《ProgrammingfromtheGroundUp》学习第1天,p1-18总结,总计18页。一、技术总结1.fetch-executecyclep9,TheCPUreadsininstructionsfrommemoryoneatatimeandexecutesthem.Thisisknownasthefetch-executecycle。2.general-purposevsspecial-purpose(......
  • 494.力扣每日一题6/30 Java(三种解法)
    博客主页:音符犹如代码系列专栏:算法练习关注博主,后期持续更新系列文章如果有错误感谢请大家批评指出,及时修改感谢大家点赞......
  • 牛客周赛49
    比赛链接:牛客周赛49赛时感受A思路    代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglongconstintN=1e5+10;intmain(){lla,b;cin>>a>>b;cout<<a-b*11<<endl;return0;}B思路......
  • 代码随想录算法训练营第49天 | 300.最长递增子序列 、674. 最长连续递增序列 、718.
    300.最长递增子序列今天开始正式子序列系列,本题是比较简单的,感受感受一下子序列题目的思路。视频讲解:https://www.bilibili.com/video/BV1ng411J7xPhttps://programmercarl.com/0300.最长上升子序列.html/***@param{number[]}nums*@return{number}*/varlengthOfL......
  • 动手学深度学习(Pytorch版)代码实践 -计算机视觉-49风格迁移
    49风格迁移读入内容图像:importtorchimporttorchvisionfromtorchimportnnimportmatplotlib.pylabaspltimportliliPytorchaslpfromd2limporttorchasd2l#读取内容图像content_img=d2l.Image.open('../limuPytorch/images/rainier.jpg')plt.im......
  • Codeforces Round 954 (Div. 3)
    A.XAxis题意:给3个x轴上的点xi,我们要放置一个点到x轴上,到这3个点的距离最短。(1<=xi<=10)思路:直接暴力破解即可inta,b,c;inlineintcal(intx){ returnabs(x-a)+abs(x-b)+abs(x-c);}voidsolve(){ cin>>a>>b>>c; intans=(int)1e9; for......
  • Day 28 | 491.递增子序列 、46.全排列、 47.全排列 II
    491.递增子序列本题和大家刚做过的90.子集II非常像,但又很不一样,很容易掉坑里。https://programmercarl.com/0491.递增子序列.html视频讲解:https://www.bilibili.com/video/BV1EG4y1h78v给你一个整数数组nums,找出并返回所有该数组中不同的递增子序列,递增子序列中至少有两......
  • ctfshow web 其他 web432--web449
    web432过滤了os|open|system|read|eval?code=str(''.__class__.__bases__[0].__subclasses__[185].__init__.__globals__['__builtins__']['__imp'+'ort__']('o'+'s').__dict__['po'+'pen'](......
  • kedaOJ#P2849时间涟漪
    题目kedaOJ#P2849时间涟漪思路栈代码#include<bits/stdc++.h>usingnamespacestd;intmain(){intN;cin>>N;stack<int>timeRipples;intmaxEnergy=INT_MIN;for(inti=0;i<N;++i){intinstruction;......
  • [题解]AT_abc249_f [ABC249F] Ignore Operations
    思路反悔贪心套路题。发现一个性质,当一个操作1生效意味着在这一步之前的所有操作都没用。那么考虑倒着枚举,对于每一个操作1的选取状态做一个简单的分讨:如果保留,那么这种情况下的答案就是之前的\(sum\)加上当前的\(y\)。如果不保留,继续往前走,\(k\leftarrowk-1\)。......