Codeforces Round #815 (Div. 2) (A~D1题解)

A题链接

题目大意:
a b c d abcd abcd 四个值,两个人的得分分别为 a / b , c / d a/b,c/d a/bc/d
一个操作: c , d c,d cd 乘一个数,使得两人得分相等,但是d不能乘0.
问最少操作几次让两人得分相等。

解题思路:
1,判断 a a a b b b 都是0的情况
2,判断 a a a b b b 有一个是0的情况
3,判断 a ∗ d a*d ad c ∗ b c*b cb 是否是倍数

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
#define PIP pair<int,pair<int,int>>
using namespace std;
 
const int N=1e5+10;
vector<int> v[N];
int a[N];
 
void solve()
{
	LL a,b,c,d;
	cin>>a>>b>>c>>d;
	
	if(a==0&&c==0)
		cout<<0<<endl;
	else if(a==0||c==0)
		cout<<1<<endl;
	else{
		a*=d;
		c*=b;
		if(a==c)
			cout<<0<<endl;
		else if(c%a==0||a%c==0)
			cout<<1<<endl;
		else cout<<2<<endl;
	}
	
}

B题链接

题目大意:
m a x ( a 1 , a 2 , . . . . , a l − 1 , a r + 1 , . . . , a n ) − m i n ( a 1 , a 2 , . . . . , a l − 1 , a r + 1 , . . . , a n ) + m a x ( a l , a l + 1 , . . . . , a r ) − m i n ( ( a l , a l + 1 , . . . . , a r ) ) max(a_1,a_2,....,a_{l-1},a_{r+1},...,a_n)-min(a_1,a_2,....,a_{l-1},a_{r+1},...,a_n)+max(a_l,a_{l+1},....,a_r)-min((a_l,a_{l+1},....,a_r)) max(a1,a2,....,al1,ar+1,...,an)min(a1,a2,....,al1,ar+1,...,an)+max(al,al+1,....,ar)min((al,al+1,....,ar))
求上式最大值

解题思路:
只需要让(最大值+次大值)-(最小值+次小值)就可以了

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
#define PIP pair<int,pair<int,int>>
using namespace std;
 
const int N=1e5+10;
vector<int> v[N];
LL a[N];
 
void solve()
{
	int n;
	cin>>n;
	rep(i,1,n)
		cin>>a[i];
	
	sort(a+1,a+1+n);
	cout<<a[n]+a[n-1]-a[1]-a[2]<<endl;
}

C题链接

题目大意:
每次可以取一个2*2的区域,然后让一个 L L L 型的区域的数字都变成 0 0 0,问最多操作次数

解题思路:
枚举1
如果有连续的0,就看看是不是全是1(如果有输出 a n s − 2 ans-2 ans2 ,否则输出 a n s − 1 ans-1 ans1
否则就输出枚举的1的个数 a n s ans ans

代码如下:

//B站关注 柚恩不加糖 捏,关注柚恩不加糖谢谢捏 
#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
#define PIP pair<int,pair<int,int>>
using namespace std;

const int N=510;
char g[N][N];
bool bo;
int dx[4]={0,1,1,1},dy[4]={1,0,-1,1};
int n,m;

void check(int x,int y){
	rep(k,0,3){
		int a=x+dx[k],b=y+dy[k];
		if(a<1||a>n||b<1||b>m)
			continue;
		if((g[x][y]-'0')+(g[a][b]-'0')==0)
			bo=1;
	}
}

void solve()
{
	
	cin>>n>>m;
	rep(i,1,n)
		cin>>g[i]+1;
	
	int ans=0;
	rep(i,1,n)
		rep(j,1,m){
			ans+=g[i][j]-'0';
			check(i,j);
		}
	
	if(bo)
		cout<<ans<<endl;
	else if(ans==n*m)
		cout<<ans-2<<endl;
	else cout<<ans-1<<endl;
	
	bo=0;
}

D1链接

题目大意:
找到最长的序列
对于任意 1 ≤ p ≤ m − 1 1≤p≤m-1 1pm1 ,满足 a b p ⨁ b p + 1 < a b p + 1 ⨁ b p a_{b_p}\bigoplus b_{p+1}<a_{b_{p+1}}\bigoplus b_p abpbp+1<abp+1bp

解题思路:
dp
从i开始往前枚举400个数就可以(好像有人枚举1000个数也过了),满足 a ( j ) ⨁ ( i − 1 ) < ( j − 1 ) ⨁ a ( i ) a(j)\bigoplus(i-1)<(j-1)\bigoplus a(i) a(j)(i1)<(j1)a(i), 就让 d p ( i ) = m a x ( d p ( i ) , d p ( j ) + 1 ) dp(i)=max( dp(i),dp(j)+1 ) dp(i)=max(dp(i),dp(j)+1)

代码如下:

//B站关注 柚恩不加糖 捏,关注柚恩不加糖谢谢捏 
#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
#define PIP pair<int,pair<int,int>>
using namespace std;

const int N=3e5+10;
int a[N];
int dp[N];

void solve()
{
	int n,ans=-INF;
	cin>>n;
	rep(i,1,n)
		cin>>a[i],dp[i]=1;
	
	rep(i,1,n){
		for(int j=max(1,i-400);j<i;j++)
			if((a[j]^(i-1))<((j-1)^a[i]))
				dp[i]=max(dp[i],dp[j]+1);
		ans=max(ans,dp[i]);
	}
		
	cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值