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

Problem - A - Codeforces

签到题,判断s里面最多能够有多少个n^{2}

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using namespace std;
using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/

void solve() {
	i64 n, s;
	cin >> n >> s;
	cout << s / (n * n) << endl;
	return;
}
signed main() {
	IOS1;
	// IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*
25820
*/

Problem - B - Codeforces

先进行排序,然后就是双指针问题,一前一后,判断有没有符合题意的,标红的和大于标蓝的和,标红的数量小于标蓝的数量

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using namespace std;
using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	i64 sum1 = 0, sum2 = 0;
	bool ok = false;
	for (int i = 0, j = n - 1; i < j; ) {
		if (a[i] + sum1 < sum2 + a[j]) {
			if (i + 1 > n - j) {
				ok = true;
				break;
			}
			else {
				sum1 += a[i];
				i++;
			}
		}
		else {
			sum2 += a[j];
			j--;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return;
}
signed main() {
	IOS1;
	// IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*
25820
*/

Problem - C - Codeforces

要求n由不同的2的次方或者某数的阶乘组成,可以知道n的取值范围最多到14!,所以可以先枚举阶乘,再用c++的__builtin_popcountll()数一数剩下需要多少个2的次方,那么就是用14位来表示用谁的阶乘,0表示不用,1表示用,而且m只有大于等于0的时候才更新答案,小于0没意义

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <queue>
// #include <deque>
// #include <stack>
// #include <string>
// #include <cstring>
// #include <numeric>
// #include <functional>
// #include <cstdlib>
// #include <vector>
// #include <set>
// #include <map>
// #include <algorithm>
// #include <cmath>
// #include <iomanip>
using namespace std;
using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef long long ll;
// typedef long long i64;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
i64 a[20];
void solve() {
	i64 n;
	cin >> n;
	int ans = INF;
	for (int i = 0; i < (1 << 14); i++) {
		i64 m = n;
		for (int j = 0; j < 14; j++) {
			if (i >> j & 1) {
				m -= a[j + 1];
			}
		}
		if (m >= 0) {
			ans = min(ans, __builtin_popcount(i) + __builtin_popcountll(m));
		}
	}
	cout << ans << endl;
	return;
}
signed main() {
	IOS1;
	// IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	a[0] = 1;
	for (int i = 1; i <= 14; i++) {
		a[i] = a[i - 1] * i;
	}
	int __t = 1;
	cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*
25820
*/

愿有那么一天,我也能六分钟签完div2的abc

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值