Codeforces Round #723 (Div. 2)

晚晚上号

A. Mean Inequality

题解
排序,从左往右,奇数位放最大,偶数为放最小,然后一路放上去放满2*n个数即可。题目说明了必定有一组b满足条件。

code:

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>T;
}

int n;
int a[105];
int b[105];

void work()
{
	cin>>n;
	for(int i=1;i<=2*n;i++)
	  cin>>a[i];
	sort(a+1,a+2*n+1);
	if(n==1)
	{
		cout<<a[1]<<' '<<a[2]<<"\n";
		return ;
	}
	int l=1,r=2*n;
	for(int i=1;i<=2*n;i++)
	{
		if(i%2==0)
		{
			b[i]=a[l];
			l++;
		}
		else
		{
			b[i]=a[r];
			r--;
		}
	}
	for(int i=1;i<=2*n;i++)
	  cout<<b[i]<<' ';
	cout<<'\n';
}

int main()
{
    ready();
    while(T--)
      work();
     return 0;
}

B. I Hate 1111

题解

可以观察出,1111=11 * 101 , 111111=111 * 1001。
每个有奇数的2的倍数的1都可以被111替代,偶数个2的倍数的1都可以被11替代,所以整条式子可以变成 a1 * 11 + a2 * 111 = n了。
然后只需要枚举出可以满足的a1,a2,就可以找到答案

 #include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>T;
}

int n;
int a[8]={1,11,111,11111,111111,1111111,11111111,111111111};
queue<int> q;
bool work()
{
	int x;
	cin>>x;
	for(int i=0;i<=x;i=i+111)
	  if((x-i)%11==0)
	    return true;
	return false;
}

int main()
{
    ready();
    while(T--)
    {
    	if(work())
    	  cout<<"YES\n";
    	else
    	  cout<<"NO\n";
	}
     return 0;
}

C2. Potions (Hard Version)

题解

应该是叫反悔贪心吧。
每次遇到正数就取,遇到负数如果取了仍为正数,那就继续取。
如果遇到负数取了整个和变成负数了,那么就找以前取过的负数之中最小的,也就是最负的离0最远的,不取那个值改而取现在的这个值,这样子反悔贪心。

code:

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    T=1;
}


int n;
long long Ans,sum;
priority_queue<int> q; 
void work()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long a;
		cin>>a;
		//cout<<sum<<endl;
		if(a>=0)
		{
			sum+=a;
			Ans++;
			continue;
		}
		else
		{
			if(sum+a>=0)
			{
				sum+=a;
				Ans++;
				q.push(-a);
				continue;
			}
			else
			{
				if(!q.empty() && -a<q.top())
				{
					sum+=q.top()+a;
					q.pop();
					q.push(-a);
				}
			}
		}
	}
	cout<<Ans;
	
}

int main()
{
    ready();
    while(T--)
      work();
     return 0;
}
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值