Codeforces Round #613 (Div. 2)
Posted jiaaaaaaaqi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #613 (Div. 2)相关的知识,希望对你有一定的参考价值。
Mezo Playing Zoma
[
Time Limit: 1 squad Memory Limit: 256 MB
]
可以到达的最左是 (-L个数),最右是 (R个数),所以答案就是相减一下。
view
/***************************************************************
> File Name : a.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2020/1/10 22:04:03
***************************************************************/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << #x << " = " << (x) << endl
#define mes(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
int n, m;
int cas, tol, T;
char s[maxn];
int main() {
// freopen("in", "r", stdin);
scanf("%d", &n);
scanf("%s", s+1);
int x = 0, y = 0;
for(int i=1; i<=n; i++) {
x -= s[i]=='L';
y += s[i]=='R';
}
printf("%d
", y-x+1);
return 0;
}
Just Eat It!
[
Time Limit: 1 squad Memory Limit: 256 MB
]
对于第二个人肯定是抛弃左边一侧或者右边一侧的若干个数字,所以只需要判断是否存在前缀或者后缀小于等于0即可。
view
/***************************************************************
> File Name : b.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2020/1/10 22:07:25
***************************************************************/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << #x << " = " << (x) << endl
#define mes(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
int n, m;
int cas, tol, T;
int a[maxn];
bool solve() {
ll ans = 0;
for(int i=1; i<=n; i++) {
ans += a[i];
if(ans <= 0) return false;
}
ans = 0;
for(int i=n; i>=1; i--) {
ans += a[i];
if(ans <= 0) return false;
}
return true;
}
int main() {
// freopen("in", "r", stdin);
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i=1; i<=n; i++) {
scanf("%d", &a[i]);
}
puts(solve() ? "YES" : "NO");
}
return 0;
}
Fadi and LCM
[
Time Limit: 1 squad Memory Limit: 256 MB
]
先质因子分解,然后就得到了若干个数把他们分配到两个数字上,由于数字只会有 (11) 个,因为前 (12) 个素数相乘就超过 (1e12) 了,所以可以直接暴力状压或者暴力 (01) 背包。
view
/***************************************************************
> File Name : c.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2020/1/10 22:13:23
***************************************************************/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << #x << " = " << (x) << endl
#define mes(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int maxn = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll n, m;
int cas, tol, T;
bool dp[maxn];
int main() {
// freopen("in", "r", stdin);
scanf("%lld", &n);
vector<ll> g;
for(ll i=2; i*i<=n; i++) {
if(n%i==0) {
ll res = 1;
while(n%i==0) {
res *= i;
n /= i;
}
g.pb(res);
}
}
if(n!=1) g.pb(n);
g.pb(1);
sort(g.begin(), g.end());
tol = g.size();
ll ans = 1;
for(int i=0; i<tol; i++) ans *= g[i];
ll n = 0;
for(; n*n<=ans; n++);
mes(dp, 0);
dp[1] = 1;
for(int i=0; i<tol; i++) {
for(ll j=n-1; j>0; j--) {
if(j%g[i]==0) dp[j] |= dp[j/g[i]];
}
}
for(ll i=n-1; i>0; i--) {
if(dp[i]) return 0*printf("%lld %lld
", i, ans/i);
}
return 0;
}
Dr. Evil Underscores
[
Time Limit: 1 squad Memory Limit: 256 MB
]
先建 (01) 字典树,然后从高位到低位开始贪心,如果字典树某个节点同时存在 (0) 和 (1) 的边,那么不管 (X) 这一位是 (0) 或者 (1),总会与一个数字 (xor) 出来后,这一位为 (1),其他情况都可以使这一位为 (0),一直贪心到根即可。
view
/***************************************************************
> File Name : d.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2020/1/10 22:53:46
***************************************************************/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << #x << " = " << (x) << endl
#define mes(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
int n, m;
int cas, tol, T;
int a[maxn];
int node[maxn*30][2];
void insert(int x) {
int root = 0;
for(int i=30; i>=1; i--) {
int k = x&(1ll<<(i-1)) ? 1 : 0;
if(node[root][k]==0) {
mes(node[++tol], 0);
node[root][k] = tol;
}
root = node[root][k];
}
}
ll dfs(int root, int deep) {
if(deep == 0) return 0;
ll ans = 0;
if(node[root][0] && node[root][1])
ans += (1ll<<(deep-1));
ll tmp = INF;
if(node[root][0]) tmp = min(tmp, dfs(node[root][0], deep-1));
if(node[root][1]) tmp = min(tmp, dfs(node[root][1], deep-1));
return tmp+ans;
}
int main() {
// freopen("in", "r", stdin);
tol = 0;
scanf("%d", &n);
for(int i=1; i<=n; i++) {
scanf("%d", &a[i]);
insert(a[i]);
}
ll ans = dfs(0, 30);
printf("%lld
", ans);
return 0;
}
以上是关于Codeforces Round #613 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #613 (Div. 2)
Codeforces Round #613 (Div. 2) B. Just Eat It!
Codeforces Round #613 (Div. 2)D(贪心,分治)
Codeforces Round #613 (Div. 2) D. Dr. Evil Underscores
Codeforces Round #613 (Div. 2) B. Just Eat It!
Codeforces Round #613 (Div. 2) D - Dr. Evil Underscores(思维,位运算)