Codeforces Round #741 (Div. 2)

题目链接

md,要不是卡B卡了一个小时,铁上分,***。文明用语哦该,发泄一下也不为过吧,呜呜

先写D1,多给两分钟就能过,思路最后一分钟猜对了

  • D1
  • 思路
    为什么不知道,可是就是猜对了,首先猜最多不会超过 2 2 2 次;大概意思就是一个位置删除之后反转的话会抵消好多。然后就猜奇偶,然后呢,还个 p p p 然后,就过了,多给两分钟就过了
  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
	int n;cin>>n;int q;cin>>q;
	string s;cin>>s;
	vector<int> pre(n+1);
	for(int i=1;i<n;i+=2){
		if(s[i]=='+') s[i]='-';
		else s[i]='+';
	}
	// cout<<s<<endl;
	for(int i=0;i<n;i++){
		if(s[i]=='+'){
			pre[i+1]=pre[i]+1;
		}
		else{
			pre[i+1]=pre[i]-1;
		}
	}
	while(q--){
		int l,r;cin>>l>>r;
		if(l==r){
			cout<<1<<endl;continue;
		}
		int k=abs(pre[r]-pre[l-1]);
		//别忘了加个abs,负奇数给的是负一
		if(k==0){
			cout<<0<<endl;
		}
		//或者把这里改成if(k%2)
		else if(k%2==1){
			cout<<1<<endl;
		}
		else{
			cout<<2<<endl;
		}
	}
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

  • A
  • 思路
    找最大的模后值,肯定在大于等于 n / 2 n/2 n/2 后面找。
  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
void solve()
{
	ll l,r;cin>>l>>r;
	if(r%2==0){
		ll a=r;
		ll b= max(r/2+1,l);
		cout<<(a%b)<<endl;
	}
	else
	{
		ll a=r;
		ll b=max(l,(r+1)/2);
		cout<<(a%b)<<endl;
	}
	
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}
  • B
  • 思路
    在这里插入图片描述
    md,就是因为他。
    直接构造其实, 1   4    6    8   9 1 ~4~ ~6~ ~8~ 9 1 4  6  8 9 出现了,直接输出他们;0出现了输出 s [ 0 ] + 0 s[0]+0 s[0]+0
    如果 2   3   5   7 2 ~3~ 5~ 7 2 3 5 7出现了 2 2 2 次,直接输出xx;剩下的还有   27   57 ~27 ~57  27 57 537 537 537 wuwuuwuwuwuwuuw, 57 57 57 就够了。
  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
	int k;cin>>k;
		string s;cin>>s;
		for(int i=0;i<10;i++){
			vis[i]=0,p[i]=-1;
		}
		for(int i=0;i<s.size();i++){
			int tx=s[i]-'0';
			if(p[tx]==-1) p[tx]=i;
			vis[tx]++;
		}
		if(vis[1]) {
			cout<<1<<endl;cout<<1<<endl;return;
		}
		
		for(int i=4;i<=9;i+=2){
			if(vis[i]){
				cout<<1<<endl;
				cout<<i<<endl;return;
			}
		}
		
		if(vis[9]){
			cout<<1<<endl;cout<<9<<endl;return;
		}
		if(vis[0]){
			cout<<2<<endl;cout<<s[0]<<0<<endl;return;
		}
		if(vis[2]>=2){
			cout<<2<<endl;cout<<22<<endl;return;
		}
		if(vis[3]>=2){
			cout<<2<<endl;cout<<33<<endl;return;
		}
		if(vis[5]>=2){
			cout<<2<<endl;cout<<55<<endl;return;
		}
		if(vis[7]>=2){
			cout<<2<<endl;cout<<77<<endl;return;
		}
		if(vis[2]){
			if(p[2]!=0){
				cout<<2<<endl;
				cout<<s[0]<<2<<endl;return;
			}
		}
		if(vis[2]&&vis[7]&&p[2]<p[7]){
			cout<<2<<endl;cout<<27<<endl;return;
		}
		
		if(vis[5]){
			if(p[5]!=0){
				cout<<2<<endl;
				cout<<s[0]<<5<<endl;return;
			}
		}
		
		if(vis[5]){
			cout<<2<<endl;
			cout<<57<<endl;
		}
		
	
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}
  • C
  • 思路
    如果全是 1 1 1,随便输出两个长度相等的;否则找到 0 0 0 的位置,输出,因为后面差个 0 0 0 ,正好是二倍的关系,前面差个 0 0 0,那就是相等。
  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
	int n;cin>>n;
	string s;cin>>s;
	int p=-1;
	
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			p=i;break;
		}
	}
	if(p==-1){
		cout<<1<<" "<<n-1<<" "<<2<<" "<<n<<endl;return;
	}
	p++;
	// cout<<p<<" "<<n/2<<endl;
	
	// else{
		if(p<=n/2){
			cout<<p<<" "<<n<<" "<<p+1<<" "<<n<<endl;
		}
		else{
			cout<<1<<" "<<p<<" "<<1<<" "<<p-1<<endl;
		}
	// }
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

疯狂的码泰君

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

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

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

打赏作者

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

抵扣说明:

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

余额充值