# Codeforces Round #653 (Div. 3)

## Required Remainder

### Coding

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-7;

ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-')  f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (48 ^ c);
c = getchar();
}
return f * x;
}

const int N = 1e6 + 10;

char str[N];

int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(_--) {
ll l = 0, r = 1e9 + 10;
while(l < r) {
ll mid = l + r + 1 >> 1;
if(mid * x + y <= n)  l = mid;
else r = mid - 1;
}
printf("%lld\n", l * x + y);
}
return 0;
}


## Multiply by 2, divide by 6

### Coding

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-7;

ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-')  f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (48 ^ c);
c = getchar();
}
return f * x;
}

const int N = 1e6 + 10;

char str[N];

int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(_--) {
int num2 = 0, num3 = 0;
while(n % 3 == 0) {
n /= 3;
num3++;
}
while(n % 2 == 0) {
n /= 2;
num2++;
}
//最后n不是1说明还存在其他的质因子。
if(n != 1 || num2 > num3) puts("-1");
else  printf("%d\n", num3 + num3 - num2);
}
return 0;
}


## Move Brackets

### Coding

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-7;

ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-')  f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (48 ^ c);
c = getchar();
}
return f * x;
}

const int N = 1e6 + 10;

char str[N];

int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _; cin >> _;
while(_--) {
int n; cin >> n;
stack<char> stk;
for(int i = 1; i <= n; i++) {
char temp;  cin >> temp;
if(stk.empty() || stk.top() == temp || temp == '(')  stk.push(temp);
else  stk.pop();
}
printf("%d\n", stk.size() / 2);
}
return 0;
}


## Zero Remainder Array

### Coding

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-7;

ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-')  f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (48 ^ c);
c = getchar();
}
return f * x;
}

const int N = 2e5 + 10;

int a[N];

int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(_--) {
for(int i = 1; i <= n; i++) {
a[i] %= k;
}
sort(a + 1, a + 1 + n, greater<int> ());
int now_num = 1, ansn = a[1], num = 1;
for(int i = 2; i <= n && a[i] != 0; i++) {
if(a[i] == a[i - 1])  now_num++;
else  now_num = 1;
if(now_num >= num)  ansn = a[i], num = now_num;
}
if(ansn == 0){
puts("0");
continue;
}
// cout << num << " " << ansn << endl;
printf("%lld\n", 1ll * k * (num - 1) + k - ansn + 1);
}
return 0;
}


### Code

#include <bits/stdc++.h>
#define mp make_pair
// #define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-7;

ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-')  f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (48 ^ c);
c = getchar();
}
return f * x;
}

const int N = 2e5 + 10;

struct Node {
int value, fa, fb;
void input() {
}
void out() {
printf("%d %d %d\n", value, fa, fb);
}
bool operator < (const Node & t) const {
return value < t.value;
}
}a[N], b[N], c[N], in;
//结构体就是数组的用处，不用管。是我自己一开始思路想的有点复杂，然后就写了这么一个结构体。

int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n = read(), k = read(), na = 0, nb = 0, nc = 0;
for(int i = 1; i <= n; i++) {
in.input();
if(in.fa && in.fb)  c[++nc] = in;
else if(in.fa)  a[++na] = in;
else if(in.fb)  b[++nb] = in;
//一定要注意特判 0 0的情况。
}
// cout << na << " " << nb << " " << nc << endl;
sort(a + 1, a + 1 + na);
sort(b + 1, b + 1 + nb);
sort(c + 1, c + 1 + nc);
int pa = 1, pb = 1, pc = 1, flag = 0;
int numa = 0, numb = 0;
ll ans = 0;
while(pa <= na && pb <= nb && pc <= nc) {
if(a[pa].value + b[pb].value <= c[pc].value) {
ans += a[pa].value + b[pb].value;
pa++, pb++;
}
else {
ans += c[pc].value;
pc++;
}
numa++, numb++;
if(numa >= k && numb >= k) {
flag = 1;
break;
}
}
// cout << ans << " " << numa << " " << numb << endl;
if(flag) {
printf("%lld\n", ans);
return 0;
}
if(pa > na || pb > nb) {
while(pc <= nc) {
ans += c[pc].value;
pc++;
numa++, numb++;
if(numa >= k && numb >= k) {
flag = 1;
break;
}
}
}
else {
while(pa <= na && pb <= nb) {
ans += a[pa].value + b[pb].value;
pa++, pb++;
numa++, numb++;
if(numa >= k && numb >= k) {
flag = 1;
break;
}
}
}
if(flag) {
printf("%lld\n", ans);
return 0;
}
puts("-1");
return 0;
}


06-29 1530

06-29 127

03-09 1万+

03-24 1万+

04-01 538

06-29 277

06-29 62

#### 【Codeforces Round #653 (Div. 3)】 A-D 详解

©️2020 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客

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