Codeforces Round #774 (Div. 2) A-C

2022/3/6 6:16:45

本文主要是介绍Codeforces Round #774 (Div. 2) A-C,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

A

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1e6+10,INF=1e8;
int a[N];
int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		ll n,s;
		scanf("%lld%lld", &n,&s);
		n *= n;
		printf("%lld\n", s / n);
	}
	return 0;
}

B

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+10,INF=1e8;
ll a[N];
int main()//红名大佬的题解
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
        int n,f=0;
        scanf("%d", &n);
        for (int i = 1; i <= n;i++)
        {
            scanf("%lld", &a[i]);
        }
        sort(a + 1, a + 1 + n);
        ll l = 2, r = n, ans = a[n] - a[1] - a[2];
        while(l<r)
        {
            if(ans>0) {
                f = 1;
                break;
            }
            ans += a[--r] - a[++l];
        }
        if(f)
            printf("YES\n");
        else
            printf("NO\n");
    }
	return 0;
}
/*我的题解
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+10,INF=1e8;
ll a[N],s[N];
int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		int n;
		ll sum = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n;i++)
		 	s[i] = 0;
		for (int i = 1; i <= n  ;i++)
		{
			scanf("%lld", &a[i]);
		}
		sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n;i++)
		{
			s[i] = s[i - 1] + a[i];
		}
		int k = n / 2;
		if(n%2==0)
		{
			int i = n - 1,f=0;
			for (int j = 2; j <= k + 1; j++)
			{
				if(s[n]-s[i]<=s[j])
				{
					if(i>k+1) i--;
					else
					{
						printf("NO\n");
						break;
					}
				}
				else
				{
					printf("YES\n");
					break;
				}
			}
		}
		else
		{
			if(s[n]-s[k+1]>s[k+1])
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

*/

C

参考知乎,位运算的使用,对于每个数可以枚举到2的15次方,然后用n=1!+2!+3!...+t表示,最后把t拆成2的几次幂,即算一下t里有几个1加一起取最小值。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;
typedef long long ll;
const int N=1e5+10,INF=1e8;
ll fac[20];
int main()
{
	int t;
	ll res = 1;
	scanf("%d", &t);
	for (int i = 1; i <= 15;i++)
	{
		res *= i;
		fac[i - 1] = res;
	}
	while (t--)
	{
	    ll n;
	    int ans = 1000;
	    scanf("%lld", &n);
	    for (int i = 0; i < 1 << 15; i++)
	    {
		bitset<15> b(i);
	        ll t = n;
		for (int j = 0; j < 15;j++)
		    t -= fac[j] * b[j];
		if(t>=0)
		{
			bitset<64> b1(t);
			ans = min(ans,(int)(b1.count() + b.count()));
		}
	    }
	printf("%d\n", ans);
	}
	return 0;
}




这篇关于Codeforces Round #774 (Div. 2) A-C的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程