Codeforces Round 924 (Div. 2)(A-C)

本文介绍了三个编程题目:RectangleCutting涉及奇偶性判断矩阵的构造,Equalize采用贪心策略解决数组相等子序列问题,PhysicalEducationLesson通过数学分析确定物理教育课例中的因子和去重。
摘要由CSDN通过智能技术生成

A:Rectangle Cutting

让a>b对于能构成的要不都是偶数要不一个是偶数但除以二不等于另一个

求出能构造出的矩阵,判断与之前是否相等

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
const int mod=1e9+7;
int a[N];
void solve(){
   int a,b;
   cin>>a>>b;
   if(a==1&&b==1) cout<<"NO"<<endl;
   else if(a%2==0&&b%2==0) cout<<"YES"<<endl;
   else if((a%2==0&&a!=b*2)||(b%2==0&&a*2!=b)) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

B:Equalize

贪心,先排序,去重,发现能相等的值在一个滑动窗口,只要求出大于a[i]+n位置然后进行求出两者之间的数目即可

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
const int mod=1e9+7;
int a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    int res=0;
    sort(a,a+n);
    int m=unique(a,a+n)-a;
    for(int i=0;i<m;i++){
    	int g=lower_bound(a,a+m,a[i]+n)-a;
    	res=max(g-i,res);
	}
	cout<<res<<endl;
    
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

C:Physical Education Lesson

这道题先用数学来分析

如果是在前半段的话 (2*k-2)*m=n-x 满足大于x

那么k必须是n-x因子

如果在后半段的话 (2*k-2)*m=n-x+2满足大于x

防止有重复的用set去重

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
const int mod=1e9+7;
void solve(){
    int n,x;
    cin>>n>>x;
    set<int>s;
    int g=n-x;
    for(int i=1;i<=g/i;i++){
    	if(g%i==0){
    		int a=(i+2)/2,b=(g/i+2)/2;
    		if(i%2==0&&x<=a) s.insert(a);
    		if(g/i%2==0&&x<=b) s.insert(b);
		}
	}
	g=n+x-2;
     for(int i=1;i<=g/i;i++){
    	if(g%i==0){
    		int a=(i+2)/2,b=(g/i+2)/2;
    		if(i%2==0&&x<=a) s.insert(a);
    		if(g/i%2==0&&x<=b) s.insert(b);
		}
	}
	cout<<s.size()<<endl;
    
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

多年以后

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

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

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

打赏作者

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

抵扣说明:

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

余额充值