Codeforces Round 858 (Div. 2)AB

最近感觉自己越来越菜了,思维太不活跃了,打了2个小时又只过了A题,做到B题的时候没思路,就不想思考了,思维慢慢地变的迟钝下来了,比赛还要1个小时的时候就跑路了...自己的思维太不活跃了...

唯一值得庆幸的是发现了官方题解,感觉题解是真的好啊!!!

A:Problem - A - Codeforces

这道题写了15分钟,写的好慢...啊

对于(a,b)点,它能到达的地方是以他为原点45度到180度之间的部分

然后就比较好写了..

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<map>
#include<set>
#include <utility>
using namespace std;
typedef  long  long ll ;
#define pii pair<int,int>
const int inf = 0x3f3f3f3f;//106110956
inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}
void print(__int128 num) {
	if(num) {
		print(num/10);
		putchar(num%10+'0');
	}
}
ll ex_gcd(ll a,ll b,ll& x,ll& y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}

	ll d=ex_gcd(b,a%b,y,x);
	y=y-a/b*x;
	return d;
}
int t;
ll a,b,c,d; 
int main(){
	scanf("%d",&t);
	while(t--){
		cin>>a>>b>>c>>d;
		if(d==b&&c<=a){
			printf("%lld\n",abs(c-a));
			continue;
		}
		if(d>b){
			if(c>a+d-b){
				printf("-1\n");
				continue; 
			}else{
				printf("%lld\n",abs(d-b)+a+d-b-c);
				continue;
			}
		}
		printf("-1\n");
	}


	return 0;
}


B:Problem - B - Codeforces

这题我刚开始看的时候觉得应该得先排序,在处理,然后大小穿插放,但是样例1 0 0 0 2 0 3 0,把我搞蒙了,这个排序不对啊...

我的方法是先排序,然后大小穿插,和不大小穿插这两种方法

我不穿插的情况:比如1 0 0 0 2 0 3 0,比较好的排序是0 0 0 0 0 2 1 3,然后我就统计第一个 与前面不相等的数i,然后把第 i+1和第i位置交换..反正就是非常麻烦了....,最后也没过

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<map>
#include<set>
#include <utility>
using namespace std;
typedef  long  long ll ;
#define pii pair<int,int>
const int inf = 0x3f3f3f3f;//106110956
inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}
void print(__int128 num) {
	if(num) {
		print(num/10);
		putchar(num%10+'0');
	}
}
ll ex_gcd(ll a,ll b,ll& x,ll& y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}

	ll d=ex_gcd(b,a%b,y,x);
	y=y-a/b*x;
	return d;
}
map<ll,ll>mp;
int t,n;
int a[200005];
int main(){
	scanf("%d",&t);
	while(t--){
		mp.clear();
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		} 
		
		int ans;
		int flag=0;
		sort(a+1,a+1+n);
		
		for(int i=2;i<=n;i++){
			if(a[i]!=a[i-1]&&flag==0){
			if(i<n)mp[a[i]+a[i+1]]=1;
			if(i==n)mp[a[i]+a[i-1]]=1; 
			if(i<=n-1) mp[a[i-1]+a[i+1]]=1;
				flag=1;
				
			}else{
				mp[a[i]+a[i-1]]=1;
			}		
		}
		
		for(int i=0;;i++){
			if(mp[i]==0){
				ans=i;
				break;
			}
		}	
				
		mp.clear();			
		int r=n;		
		for(int l=1;l<=r;l++){
			if(l!=r){
				mp[a[r]+a[l]]=1;
			}else{
				mp[a[r]+a[r+1]]=1; 
			}			
			r--;
		}
				
		for(int i=0;;i++){
			if(mp[i]==0){
				ans=min(ans,i);
				break;
			}
		}
		printf("%d\n",ans);
	}
	
	return 0;
}


官方题解:tips:最后的答案一定小于等于2(其实很好想的,但比赛没往这里想)

1.当答案为0时候,0的个数一定小于等于[n/2]向下取整,因为此时0中间可以被其他数穿插

比如0 1 0 1 0 1 0

2当答案为1时候,如果0的个数为n,答案为1,如果1的个数和0的个数和不为n的话,答案也为1

比如0 0 0 0 0 x 1  1 1  1

3当答案为2的时候,除了0和1的情况都输出2即可,此时0一定大于[n/2],一定有0相邻,并且一定有01相邻,如果没有1的话,就输出1了

失败总是贯穿人生始终,加油吧。

从今往后一天一场cf了,能不能坚持一年

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值