A.
赛时乱模拟写过
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+9;
int a[N];
void lan(){
ll a,b;
cin>>a>>b;
ll ta=a;
ll tb=b;
ll ans=a*b;
if(a&1 && b&1){
cout<<"No"<<'\n';
return;
}
if(a&1){
b/=2;
a*=2;
if(b==ta && a==tb){
cout<<"No"<<'\n';
return;
}
if(a*b==ans){
cout<<"Yes"<<'\n';
return;
}
}else if(b&1){
a/=2;
b*=2;
if(a==tb && b==ta){
cout<<"No"<<'\n';
return;
}
if(a*b==ans){
cout<<"Yes"<<'\n';
return;
}
}
if(!(a&1) && !(b&1)){
cout<<"Yes"<<'\n';
return;
}
cout<<"No"<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while(q--){
lan();
}
return 0;
}
B.
假设要到2->5,如果有2个2必然只有一个能加到5,因此排序去重,只要左右差值小于n-1(最少也要加1)必然有一种排序方式构成相同数字,找最大数量,双指针找
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+9;
void lan(){
int n;
cin>>n;
vector<int> v;
for(int i=1;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
//排序去重
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int ans=1;
//极差在n-1范围内就存在某种排序方式使得排列加上后得到相同数字
for(int i=0,j=0;i<v.size();i++){
while(j+1<v.size() && v[j+1]-v[i]<=n-1){
j++;
}
ans=max(ans,j-i+1);
}
cout<<ans<<'\n';
//静态数组写法
//int m=unique(a+1,a+1+n)-a-1;去重的数组长度
//for(int i=1,j=1;i<=m;i++){
// while(a[j]<a[i]+1-n){
// j++;
// }
// ans=max(ans,i-j+1);
//}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while(q--){
lan();
}
return 0;
}
C.
1.(1~k)可以知道(2k-2)*t+x=n=>n-x%(2k-2)==0;
2.(k-1~2)可以知道(2k*2)*t+k+k-x=n=>n+x-2%(2k-2)==0;
枚举n-x(1~k),n+x-2(k-1~2)的因子
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+9;
int a[N];
void lan(){
int n,x;
cin>>n>>x;
set<ll> st;
for(int i=1;i<=(n-x)/i;i++){
if((n-x)%i==0){
if(!(i&1)){
st.insert(i);
}
if(!(((n-x)/i)&1)){
st.insert((n-x)/i);
}
}
}
for(int i=1;i<=(n+x-2)/i;i++){
if((n+x-2)%i==0){
if(!(i&1)){
st.insert(i);
}
if(!(((n+x-2)/i)&1)){
st.insert((n+x-2)/i);
}
}
}
ll ans=0;
for(auto i: st){
if((i+2)/2>=x){
ans++;
}
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while(q--){
lan();
}
return 0;
}
本文讨论了C++中的两个技术问题,一是通过双指针和条件判断检查数字是否可通过交换得到相同值,二是利用排序和去重技术确定满足特定条件的序列组合数。
1725

被折叠的 条评论
为什么被折叠?



