Codeforces Round 353 (Div. 2) A Codeforces Round 514 (Div. 2) A CF1792 Min Max S

54 阅读3分钟

今天还有点小开心,终于有所突破了,呜呜呜。今天的三个题:

Problem - 675A - Codeforces

Problem - 1059A - Codeforces

Problem - 1792C - Codeforces

分析

AA:很显然的一个题,二分答案即可,就按部就班推出等差数列公式之后开始二分,最后为了防止边界问题,可以判断一下lll+1l+1两个值。

BB:也是个显然题,就按题意模拟即可,但是注意一下第一个时间也得算进去,还有最后剩余的时间,都得÷a÷a加上去。

CC:最开心的事情就是做出了这个题,虽然只有15001500,但是也算有所小突破了,这个题题意其实就是给你个乱序的1 n1~n的排序,可以任意选择两个数将其中大道放到序列末尾,小的放到序列开头,问至少几次可以将序列排成递增。经过短暂的思索和尝试,我发现突破点,奇数在于(1+n)/2(1+n)/2,偶数在于n/2,(1+n)/2n/2,(1+n)/2。我们考虑奇数,先找到中值,从中值往左右分别找,如果能在左边找到mid1mid-1,右边找到mid+1mid+1,再以此为基准点,继续寻找,直到找到尽头为止,偶数同理,找到n/2n/2n/2+1n/2+1的位置,最后我们看能找到几对有序的序列,那么我们答案就是n/2cntn/2-cnt对。实现起来我错了好多次,然后。。。双指针写假了好多次,bbzlbbzl,最后过了还行。

代码

AA:

#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long

ll a,b,c;
using namespace std;
ll f(ll n){
	return a+(n-1)*c;
}
int main(){
	IOS;
	cin>>a>>b>>c;
	ll l=1,r=2e9;
	if(c==0){
		if(b!=a) cout<<"NO";
		else cout<<"YES"; 
		return 0;
	}
	while(l<r){
		int mid=l+r>>1;
		if(c>0){
			if(f(mid)>=b) r=mid;
			else l=mid+1; 
		} 
		else{
			if(f(mid)>b) l=mid+1;
			else r=mid;
		}
		
	}
	//cout<<f(l);
	if(f(l)==b || f(l+1)==b) cout<<"YES";
	else cout<<"NO";
	return 0;
	 
} 

BB:

#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long

using namespace std;
int n,L,a;
const int N=1e5+10;
int t[N],l[N];
int main(){
	IOS;
	cin>>n>>L>>a;
	for(int i=1;i<=n;i++){
		cin>>t[i]>>l[i];
	}
	int ans=0; 
	ans+=(t[1])/a;
	for(int i=2;i<=n;i++){
		int res=t[i-1]+l[i-1];
		if(t[i]-res>=a) ans+=(t[i]-res)/a;
	}
	ans+=(L-(t[n]+l[n]))/a;
	cout<<ans;
	return 0;
	 
} 

CC:

#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long

using namespace std;
const int N=200010;
int t,n,a[N],id[N],f[N];
void solve(){
	cin>>n;
	a[0]=-10000000;
	a[n+1]=100000000;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		id[a[i]]=i;
		f[i]=a[i];
	}
		
	int cnt=0;
	if(n%2==0){
		
		int l=id[n/2],r=id[n/2+1];
		if(l<r) cnt++;
		else{
			cout<<n/2<<"\n";
			return;
		}
		int lva=n/2,rva=n/2+1;
		while(l>=1 && r<=n){
			bool ok1=false,ok2=false;
			while(l-1>=0){
				if(a[l-1]!=lva-1) l--;
				else{
					lva--;
					l--;
					ok1=true;
					break;
				}
			}
			while(r+1<=1+n){
				if(a[r+1]!=rva+1) r++;
				else{
					rva++;
					r++;
					ok2=true;
					break;
				}
			}
			if(ok1 && ok2){
				cnt++;
				ok1=false;
				ok2=false;
			}
		}
	}
	else{
		int mid=id[n/2+1],midva=n/2+1;
		if(mid==1 || mid==n){
			cout<<n/2<<"\n";
			return;
		}
		int l=mid,r=mid;
		int lva=n/2+1,rva=n/2+1;
		while(l>=1 && r<=n){
			bool ok1=false,ok2=false;
			while(l-1>=0){
				if(a[l-1]!=lva-1) l--;
				else{
					lva--;
					l--;
					ok1=true;
					break;
				}
			}
			while(r+1<=n+1){
				if(a[r+1]!=rva+1) r++;
				else{
					rva++;
					r++;
					ok2=true;
					break;
				}
			}
			if(ok1 && ok2){
				cnt++;
				ok1=false;
				ok2=false;
			}
		}
	}
	cout<<n/2-cnt<<"\n";
}
int main(){
	IOS;
	cin>>t;
	while(t--) solve(); 
	return 0;
	 
} 

加油!