Codeforces Round #592 (Div. 2)
Codeforces Round #592 (Div. 2)
A. Pens and Pencils
-
思路:水题
-
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int t, a, b, c, d, k, x, y;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t -- ){
cin >> a >> b >> c >> d >> k;
if (a % c)
x = a / c + 1;
else
x = a / c;
if (b % d)
y = b / d + 1;
else
y = b / d;
if (x + y <= k)
cout << x << " " << y << "\n";
else
cout << "-1\n";
}
return 0;
}
B. Rooms and Staircases
-
思路:模拟
-
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
int t, n, len;
bool flag;
string s;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t -- ){
cin >> n >> s;
len = s.length();
flag = false;
for (int i = 0, j = len - 1; i <= j; i ++ , j -- ){
if (s[i] == '1' || s[j] == '1'){
if (len / 2 < len - i)
cout << (len - i) * 2 << "\n";
else
cout << i * 2 << "\n";
flag = true;
break;
}
}
if (flag)
continue;
else
cout << n << "\n";
}
return 0;
}
C. The Football Season
-
思路:可以exgcd 但是暴力枚举就过辽
-
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b){
return a * b / gcd(a, b);
}
ll n, p, w, d, x, y, z;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p >> w >> d;
for (y = 0; y <= lcm(w, d) / d - 1; y ++ ){
x = (p - d * y) / w;
if (x < 0)
continue;
if (x * w + y * d != p)
continue;
z = n - x - y;
if (z < 0)
continue;
break;
}
if (y == lcm(w, d) / d)
cout << "-1\n";
else
cout << x << " " << y << " " << z << "\n";
return 0;
}
E. Minimizing Difference
-
思路:二分(最近这种题做的有点多
-
AC代码
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mult_mod(ll x, ll y, ll mod){
return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}
ll pow_mod(ll a, ll b, ll p){
ll res = 1;
while (b){
if (b & 1)
res = mult_mod(res, a, p);
a = mult_mod(a, a, p);
b >>= 1;
}
return res % p;
}
ll gcd(ll a, ll b){
return b ? gcd(b, a % b) : a;
}
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
ll n, k, l, r, mid;
ll a[N];
bool check(ll x){
ll cnt = 0, tmp = n;
for (int i = 1; i < tmp; i ++ ){
if (a[tmp] - a[i] > x)
cnt += a[tmp] - a[i] - x;
else
break;
if (cnt > k)
return false;
tmp -- ;
}
return true;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i ++ )
cin >> a[i];
sort(a + 1, a + n + 1);
r = INF;
while (r > l){
mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << "\n";
return 0;
}