AtCoder Beginner Contest 144
A - 9x9
-
思路:水题
-
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 a, b;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
if (a <= 9 && b <= 9)
cout << a * b << "
";
else
cout << "-1
";
return 0;
}
B - 81
-
思路:水题
-
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 n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
bool flag = false;
for (int a = 1; a <= 9; a ++ ){
for (int b = 1; b <= 9; b ++ ){
if (a * b == n){
flag = true;
break;
}
}
if (flag)
break;
}
if (flag)
cout << "Yes
";
else
cout << "No
";
return 0;
}
C - Walk on Multiplication Table
-
思路:暴力即可
-
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 n, tmp, ans;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
tmp = sqrt(n);
for (ll i = tmp; i >= 1; i -- ){
if (n % i == 0){
ans = i + n / i - 2;
break;
}
}
cout << ans << "
";
return 0;
}
D - Water Bottle
-
思路:两种情况比较一下即可
-
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 double pi = acos(-1);
double a, b, x, s, h, ans;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> x;
s = x / a;
if (s >= a * b / 2){
h = (a * b - s) * 2 / a;
ans = 180 * atan2(h, a) / pi;
}
else{
h = s * 2 / b;
ans = 180 * atan2(b, h) / pi;
}
printf("%.8lf
", ans);
return 0;
}
E - Gluttony
-
思路:二分 上界为最大的最小(a)(*)最大(f)
-
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 = 2e5 + 10;
ll n, k, x, l, r, mid, tmp;
vector<ll> a, f;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i ++ ){
cin >> x;
a.push_back(x);
}
for (int i = 1; i <= n; i ++ ){
cin >> x;
f.push_back(x);
}
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
for (int i = 0; i < n; i ++ )
r = max(r, a[i] * f[i]);
while (l < r){
mid = (l + r) >> 1;
tmp = 0;
for (int i = 0; i < n; i ++ )
tmp += max(0ll, a[i] - mid / f[i]);
if (tmp <= k)
r = mid;
else
l = mid + 1;
}
cout << l << "
";
return 0;
}