欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

CodeforcesRound#763B.GameonRanges

时间:2023-06-06

Problem - 1623B - Codeforces

这个题就是给出一些区间,然后每次就从该区间内取出一个数,最后能够把1...n所有数都能取一遍,求每个区间取哪个数,因为数据量比较小,可以直接暴搜

AC代码:

版本1

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize("Ofast")#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define lowbit(x) ((x) & -(x))#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 vi;typedef vector vll;typedef vector vc;template T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template T lcm(T a, T b) { return a / gcd(a, b) * b; }templateT power(T a, int b) {T res = 1;for (; b; b >>= 1, a = a * a) {if (b & 1) {res = res * a;}}return res;}const int INF = 0x3f3f3f3f;const int mod = 1000000007;void solve() {int n;cin >> n;vector l(n), r(n);for (int i = 0; i < n; i++) {cin >> l[i] >> r[i];l[i]--;}for (int i = 0; i < n; i++) {int x = l[i];for (int j = 0; j < n; j++) {if (l[i] == l[j] && r[j] < r[i]) {x = max(x, r[j]);}}cout << l[i] + 1 << " " << r[i] << " " << x + 1 << endl;}}int main() {IOS1;//IOS2;int __t = 1;cin >> __t;for (int _t = 1; _t <= __t; _t++) {solve();}return 0;}

版本2

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize("Ofast")#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define lowbit(x) ((x) & -(x))#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 vi;typedef vector vll;typedef vector vc;template T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template T lcm(T a, T b) { return a / gcd(a, b) * b; }templateT power(T a, int b) {T res = 1;for (; b; b >>= 1, a = a * a) {if (b & 1) {res = res * a;}}return res;}const int INF = 0x3f3f3f3f;const int mod = 1000000007;void solve() {int n;cin >> n;vector l(n), r(n);for (int j = 0; j < n; j++) {cin >> l[j] >> r[j];}set> st;for (int j = 0; j < n; j++) {st.insert(make_pair(l[j], r[j]));}for (int j = 0; j < n; j++) {for (int k = l[j]; k <= r[j]; k++) {bool ok = true;if (k != l[j]) {if (st.count(make_pair(l[j], k - 1)) == 0) {ok = false;}}if (k != r[j]) {if (st.count(make_pair(k + 1, r[j])) == 0) {ok = false;}}if (ok) {cout << l[j] << ' ' << r[j] << ' ' << k << endl;}}}}int main() {IOS1;//IOS2;int __t = 1;cin >> __t;for (int _t = 1; _t <= __t; _t++) {solve();}return 0;}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。