首页 > 其他分享 >Codeforces Round 964 (Div. 4)

Codeforces Round 964 (Div. 4)

时间:2024-08-12 21:05:08浏览次数:7  
标签:964 int Codeforces long leq 测试用例 maxn solve Div

Codeforces Round 964 (Div. 4)

标题

CodeForces 1999 A. A+B Again?

时限

1 second

空限

256 megabytes

题目描述

给定一个两位数的正整数 \(n\),求其数字之和。

输入

第一行包含一个整数 \(t\)(\(1\leq t\leq 90\))——测试用例的数量。

每个测试用例的唯一一行包含一个两位数的正整数 \(n\)(\(10\leq n\leq 99\))。

输出

对于每个测试用例,输出一个整数——\(n\) 的数字之和。

eazy.

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;
char s[maxn];

void solve(){
	cin>>s;
	int cnt=0;
	for(int i=0;s[i];i++){
		cnt+=s[i]-'0';
	}
	cout<<cnt<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();
		
	}
	return 0;
}

标题

CodeForces 1999 B. Card Game

时限

2 seconds

空限

256 megabytes

题目描述

苏内特和斯拉夫人玩纸牌游戏。游戏规则如下:

由于苏尼特和斯拉夫人不是最好的朋友,你需要计算苏尼特最终获胜的游戏可能发生的方式。为了更好地理解,请查看注释部分

输入

第一行包含一个整数 \(t\)(\(1\leq t\leq 10^4\))——测试用例的数量。

每个测试用例的第一行也是唯一一行包含 \(4\) 整数 \(a_1\)、\(a_2\)、\(b_1\)、\(b_2\)(\(1\leq a_1、a_2、b_1、b_2\leq 10\)),其中 \(a_1\) 和 \(a_2\) 分别表示 Suneet 拥有的卡片,\(b_1\) 和 \(b_2\) 分别表示 Slavic 拥有的卡片。

输出

对于每个测试用例,输出一个整数——考虑所有可能的游戏,Suneet 将赢得的游戏数。

这题有坑点,如果 Suneet 一局打平,一局获胜,也是他胜,1:0,2:0 都要记录。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;
int a[maxn],b[maxn];

void solve(){
	cin>>a[0]>>a[1]>>b[0]>>b[1];
	int cnt=0;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			int cnt1=0,cnt2=0;
			if(a[i]>b[j]) cnt1++;
			if(a[i^1]>b[j^1]) cnt1++;
			if(a[i]<b[j]) cnt2++;
			if(a[i^1]<b[j^1]) cnt2++;
			if(cnt1>cnt2) cnt++;
		}
	}
	cout<<cnt<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();

	}
	return 0;
}

标题

CodeForces 1999 C. Showering

时限

2 seconds

空限

256 megabytes

题目描述

作为一名计算机科学专业的学生,亚历克斯面临着一个艰巨的挑战——洗澡。他试图每天洗澡,但尽管他尽了最大的努力,总是有挑战。他洗澡需要花费 \(s\) 分钟,而一天只有 \(m\) 分钟!

他已经为当天安排了 \(n\) 的任务。任务 \(i\) 表示为间隔 \((l_i\),\(r_i)\),这意味着 Alex 很忙,无法在该时间间隔内洗澡(在 \(l_i\) 和 \(r_i\) 之间的任何时间点)没有两项任务重叠。 考虑到所有 \(n\) 的时间间隔,亚历克斯那天能洗澡吗?换句话说,亚历克斯会有一个长度至少为 \(s\) 的空闲时间间隔吗

输入

第一行包含一个整数 \(t\)(\(1\leq t\leq 10^4\))——测试用例的数量。

\(1\leq n\leq 2\cdot 10^5\), \(1\leq s,m\leq 10^9\), \(0\leq l_i<r_i\leq m\)

所有测试用例中 \(n\) 的总和不超过 \(2 \times 10^5\)。

模拟找 \(\ge s\) 的间隔即可。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;
int s,m;
int l[maxn],r[maxn];
void solve(){
	cin>>n>>s>>m;
	for(int i=1;i<=n;i++){
		cin>>l[i]>>r[i];
	}
	for(int i=1;i<=n;i++){
		if(l[i]-r[i-1]>=s){
			cout<<"Yes\n";
			return;
		}
	}
	if(m-r[n]>=s){
		cout<<"Yes\n";
		return;
	}
	cout<<"No\n";
	return;
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();
		
	}
	return 0;
}

标题

CodeForces 1999 D. Slavic's Exam

时限

2 seconds

空限

256 megabytes

题目描述

斯拉维奇的考试很难,需要你的帮助才能通过。以下是他正在努力解决的问题:

存在一个字符串 \(s\),它由小写英文字母组成,可能有零个或多个 “”。

斯拉夫语被要求将每个 “” 更改为小写英文字母,使字符串 \(t\) 成为字符串 \(s\) 的子序列(不一定是连续的)。

输出任何这样的字符串,或者说,如果不存在符合条件的字符串,则不可能输出。

如果可能有多个答案,您可以输出其中任何一个。

贪心地将问号变为当前 \(t\) 中第一个没有在 \(s\) 中出现的字符。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;
char s[maxn],t[maxn];
int suf[maxn][26];
void solve(){
	cin>>s>>t;
	int lens=strlen(s),lent=strlen(t),cnt=0;
	for(int i=lens-1;i>=0;i--){
		if(s[i]=='?'){cnt++;continue;}
		for(int j=0;j<26;j++){
			suf[i][j]=suf[i+1][j]+(s[i]-'a'==j);
		}
	}
	int pos=0;
	for(int i=0;i<lens;i++){
		if(pos>=lent) break;
		if(s[i]==t[pos]) pos++;
		else if(s[i]=='?'){
			s[i]=t[pos];
			pos++;
		}
	}
	if(pos!=lent){
		cout<<"No\n";
		return;
	}
	cout<<"Yes\n";
	for(int i=0;i<lens;i++){
		if(s[i]=='?') cout<<'a';
		else cout<<s[i];
	}
	cout<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();
		
	}
	return 0;
}

标题

CodeForces 1999 E. Triple Operations

时限

1 second

空限

256 megabytes

题目描述

Ivy 在黑板上写下了从 \(l\) 到 \(r\) 的所有整数。

在手术中,她会做以下事情:

Ivy 需要多少操作才能使董事会上的所有数字等于 0?我们有证据表明这总是可能的。

输入

第一行包含一个整数 \(t\)(\(1\leq t\leq 10^4\))——测试用例的数量。

每个测试用例的唯一一行包含两个整数 \(l\) 和 \(r\)(\(1\leq l<r\leq 2\cdot 10^5\))。

输出

对于每个测试用例,输出一个整数——使电路板上的所有数字等于 \(0\) 所需的最小操作次数。

首先将 \(l\) 变成 \(0\),然后用 \(l\) 去将其他东西变成 \(0\),答案为 \(cnt_l+\sum\limits_{i=l}^{r} cnt_i\),中间那坨用前缀和预处理即可,求 \(cnt\) 千万不要用 log,精度爆炸,喜提罚时。要直接除法模拟。

时间复杂度 \(O(r+t)\)。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;
int l,r;
int pre[maxn];
void solve(){
	cin>>l>>r;
	int ans=pre[r]-pre[l],ll=l;
	while(ll){
		ll/=3;
		ans+=2;
	}
	cout<<ans<<'\n';
	return;
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	for(int i=1;i<=200000;i++){
		int sum=0,now=i;
		while(now){
			now/=3;sum++;
		}
		pre[i]=pre[i-1]+sum;
	}
	while(T--){
		solve();
	}
	return 0;
}

标题

CodeForces 1999 F. Expected Median

时限

3 seconds

空限

256 megabytes

题目描述

Arul 有一个长度为 \(n\) 的 ** 二进制 ** 数组 。

他将取这个数组中长度为 \(k\)(\(k\) 是奇数)的所有子序列,并找到它们的中值

所有这些值的总和是多少?

由于该总和可能非常大,因此将其以 \(10^9+7\) 的模输出。换句话说,将此总和除以 \(10^9+7\) 后的余数打印出来。

标题

CodeForces 1999 G1. Ruler (easy version)

时限

1 second

空限

256 megabytes

题目描述

这是问题的简单版本。这两个版本之间的唯一区别是,在这个版本中,您最多可以进行\(\mathbf{10}\) 查询.我们有一个缺少一个数字 \(x\)(\(2\leq x\leq 999\))的秘密标尺。当你测量一个长度为 \(y\) 的对象时,标尺会报告以下值:上面的标尺缺少数字 \(4\),因此它正确地将第一段测量为长度 \(3\),但错误地将第二段测量为长 \(6\),即使它实际上是 \(5\)。

找到 \(x\) 的值。您最多可以提出 \(\mathbf{10}\) 个查询。

输入

每个测试包含多个测试用例。第一行输入包含一个整数 \(t\)(\(1\leq t\leq 1000\))——测试用例的数量。

由于查询的面积具有单调性,所以可以二分。

每次查询 ? mid mid,时间复杂度 \(O(\log_2(999)t)=O(10t)\)。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T;

void solve(){
	int l=2,r=999,ans=0;
	while(l<=r){
		int mid=(l+r)/2;
		cout<<"? "<<mid<<' '<<mid<<'\n';
		cout.flush();
		int get=0;
		cin>>get;
		if(get==mid*mid){
			l=mid+1;
		}else{
			r=mid-1;
			ans=mid;
		}
	}
	cout<<"! "<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();

	}
	return 0;
}

标题

CodeForces 1999 G2. Ruler (hard version)

时限

1 second

空限

256 megabytes

题目描述

这是问题的硬版本。

找到 \(x\) 的值。您最多可以提出 \(\mathbf{7}\) 个查询。

输入

每个测试包含多个测试用例。第一行输入包含一个整数 \(t\)(\(1\leq t\leq 1000\))——测试用例的数量。

对于一个查询 ? a b\((a<b)\),其结果有 3 种:

  • \(a\times b\),这说明缺口 \(x>b\)
  • \(a\times (b+1)\),这说明缺口 \(a<x\le b\)
  • \((a+1)\times(b+1)\),这说明缺口 \(x\le a\)

于是考虑三分。设 \(L,R\) 为三分上下界, \(l,r\) 为截点,每次查询 ? l r,然后 \(L,R\) 由上进行变动即可,但是细节多,难调

时间复杂度 \(O(\log_3(999)t)=O(7t)\)。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+3;
int n,T,m;

void solve(){
	n=999;m=1;
	while(n-m>2){
		int l=(n+2*m)/3,r=(2*n+m)/3;
		cout<<"? "<<l<<' '<<r<<'\n';
		cout.flush();
		int get;
		cin>>get;
		if(get==l*r){
			m=r;
		}else if(get==l*(r+1)){
			m=l,n=r;
		}else{
			n=l;
		}
	}
	if(n-m==2){
		cout<<"? 1 "<<m+1<<'\n';
		cout.flush();
		int get;
		cin>>get;
		if(get!=m+1) n=m+1;
		else m=m+1;
	}
	cout<<"! "<<n<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		solve();

	}
	return 0;
}

标签:964,int,Codeforces,long,leq,测试用例,maxn,solve,Div
From: https://www.cnblogs.com/DEV3937/p/18355709/cfr964

相关文章

  • AGC182 C - Sum of Number of Divisors of Product
    题目大意:求长度为1,2,...N,的好序列因数个数。好序列满足每个元素\(1\leqx\leqM\)\(N\leq1e18,M\leq16\)很容易想到维护所有好序列质因数的指数+1的乘积。\(\prodb_i,1\leqi\leq6\).考虑每个数对这个乘积的影响。假设我们只有2,3,5这三个质数,序列末端添加15,......
  • 965div2补题
    A.FindKDistinctPointswithFixedCenter思路简单构造,我居然在这个题上因为没看懂英文还有机翻英太过逆天导致我WA了好几发......ACcode:#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;voidsolve(){intx,y,k;cin>>x>>y>>k;in......
  • EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2) 补题记录(A~D1,E)
    A容易发现答案为\(\min(n,k)\min(m,k)\)。#include<bits/stdc++.h>#defineintlonglong#definepbpush_backusingnamespacestd;constintN=1000100;inta[N];signedmain(){intT;cin>>T;while(T--){intn,m,k;cin>>n&g......
  • Codeforces Round 963 (Div. 2)
    Preface有懒狗上周日的比赛拖到这周日才写博客,我不说是谁这场比赛的时候因为C数组没开两倍卡了1h最后写对拍才看出来,直接心态爆炸导致D没写完掉大分A.QuestionMarks签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>......
  • CF1998 div2 & abc366
    1CF1.1B被诈骗了。我们的构造要向“每个区间只有1个数不一样考虑”。1.2C比较难。但是出的好。注意到如果我们不删除中位数这个位置的数,那么那个数是一定的。所以我们可以把\(k\)加到最大的可以加的数上,统计答案就在这个数,然后二分算中位数即可。其它策略?我们可不......
  • Codeforces Round 965 (Div. 2) 题解
    个人难度顺序:A<D<B<C<E。A.FindKDistinctPointswithFixedCenter如果\(k\)是偶数,构造\((x_c+i,yc+i)\),其中\(-\frac{k}{2}\lei\le\frac{k}{2}\)。对于\(k\)是奇数,先加一个点\((xc,yc)\),然后就变成偶数的情况了。B.MinimizeEqualSumSubarr......
  • Codeforces Round 965 (Div. 2) 补题记录(A,B,D,E1)
    speedforcesagain~A<E1<<B<D<<CA若\(k\equiv1(\bmod2)\),则构造\((x,y)\),\((x-1,y)\),\((x+1,y)\),\((x-2,y)\),\((x+2,y)\),\(\ldots\)。否则构造\((x-1,y)\),\((x+1,y)\),\((x-2,y)\),\((x+2,y)\),\(\ldots\)。#pra......
  • Codeforces Round 964 (Div. 4)
    这场的题不错,就是一直在inqueue......
  • div-固定在页面中间,不被其他元素覆盖
    最开始设置的子元素D是text-align:center,子元素C的内容过长的时候,会发现子元素D不在页面正中了所以需要把子元素D设置成固定中间,把子元素D设置成固定中间后,发现元素B把子元素D给覆盖了一部分,所以需要在父元素A和元素B之间加一个空的div,给div设置高度后,父元素A和元素B之间的距离......
  • Codeforces 165E Compatible Numbers 题解
    思路高维前缀和高维前缀和把数的二进制看成一个集合,二进制的每一位为\(1\)为全集\(V\)。根据题目描述,若两数\(a,b\)相容,则\(a\operatorname{and}b=0\),容易发现,\(b\in\complement_{V}a\),所以我们只需要用高维前缀和处理出\(\complement_{V}a\)的一个元素即可。......