标签:team set res map min queue ace inf end
思路:水题
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 q, n;
ll x, sum;
bool flag;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
sum = 0;
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> x;
if (x <= 2048)
sum += x;
}
if (sum >= 2048)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
思路:依次间隔构造即可
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 = 110;
int n;
char mp[N][N];
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;
for (int i = 1; i <= n; i ++ ){
if (i & 1){
for (int j = 1; j <= n; j ++ ){
if (j & 1)
mp[i][j] = 'W';
else
mp[i][j] = 'B';
}
}
else{
for (int j = 1; j <= n; j ++ ){
if (j & 1)
mp[i][j] = 'B';
else
mp[i][j] = 'W';
}
}
}
for (int i = 1; i <= n; i ++ ){
for (int j = 1; j <= n; j ++ )
cout << mp[i][j];
cout << "\n";
}
return 0;
}
思路:思维题
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 q, c, m, x, min_;
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
cin >> c >> m >> x;
min_ = min(c, m);
if (c - min_ + m - min_ + x < min_)
cout << x + (c - x + m - x) / 3 << "\n";
else
cout << min_ << "\n";
}
return 0;
}
思路:线性dp
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 = 3e5 + 10;
const ll INF = 2e18;
int q, n;
int a[N], b[N];
ll dp[N][3];
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q -- ){
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> a[i] >> b[i];
dp[i][0] = dp[i][1] = dp[i][2] = INF;
}
dp[1][0] = 0, dp[1][1] = b[1], dp[1][2] = 2 * b[1];
for (int i = 2; i <= n; i ++ )
for (int j = 0; j < 3; j ++ )
for (int k = 0; k < 3; k ++ )
if (a[i] + k != a[i - 1] + j)
dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]);
cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << "\n";
}
return 0;
}
Educational Codeforces Round 73 (Rated for Div. 2)
标签:team set res map min queue ace inf end
原文地址:https://www.cnblogs.com/Misuchii/p/11801524.html