Codeforces Round #588 (Div. 2)
A. Dawid and Bags of Candies
- 思路:水题
- 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[4];
int main(){
#ifndef ONLINE_JUDGE
freopen("my_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 0; i < 4; i ++ )
cin >> a[i];
sort(a, a + 4);
if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3])
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
B. Ania and Minimizing
- 思路:模拟
- 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, k, cnt;
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 >> n >> k >> s;
if (n == 1){
if (s[0] != '0' && k == 1)
cout << "0\n";
else if (s[0] != '0' && k == 0)
cout << s << "\n";
else
cout << s << "\n";
return 0;
}
if (s[0] != '1' && cnt < k){
s[0] = '1';
cnt ++ ;
}
for (int i = 1; i < n; i ++ ){
if (cnt >= k)
break;
if (s[i] != '0'){
s[i] = '0';
cnt ++ ;
}
}
cout << s << "\n";
return 0;
}
C. Anadi and Domino
- 思路:按着题意做就行了
- 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 = 10;
const int INF = 0x3f3f3f3f;
int n, m, a, b, ans, res;
int 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 >> m;
for (int i = 1; i <= m; i ++ ){
cin >> a >> b;
mp[a][b] = mp[b][a] = 1;
}
if (n <= 6){
cout << m << "\n";
return 0;
}
ans = INF;
for (int i = 1; i <= n; i ++ ){
for (int j = i + 1; j <= n; j ++ ){
res = 0;
for (int k = 1; k <= n; k ++ )
if (mp[i][k] && mp[j][k])
res ++ ;
ans = min(ans, res);
}
}
cout << m - ans << "\n";
return 0;
}
D. Marcin and Training Camp
- 思路:暴力把所有可以的搞出来 然后同时标记子集
- 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 = 7010;
ll n, ans;
ll a[N], b[N];
map<ll, ll> mp;
set<ll> st;
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 ++ ){
cin >> a[i];
++ mp[a[i]];
}
for (int i = 1; i <= n; i ++ )
cin >> b[i];
for (auto it: mp)
if (it.second > 1)
for (int i = 1; i <= n; i ++ )
if ((it.first | a[i]) == it.first)
st.insert(i);
for (auto it: st)
ans += b[it];
cout << ans << "\n";
return 0;
}
原文地址:https://www.cnblogs.com/Misuchii/p/11801521.html
时间: 2024-10-23 09:19:47