Codeforces Round #491 (Div.2)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #491 (Div.2)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
get
- 被精度坑死了(B,C).遇到精度問題看能不能轉(zhuǎn)化為整數(shù),不行的話就用eps判斷
A. If at first you don’t succeed…
題意
有兩個(gè)聚會(huì),A個(gè)人去第一個(gè)聚會(huì),B個(gè)人去第二個(gè)聚會(huì),C個(gè)人兩個(gè)都去了,一共有N個(gè)人,至少有一個(gè)人一個(gè)聚會(huì)也沒有去,問一共有幾個(gè)人沒有去聚會(huì),如果無解輸出-1
AC
#include <bits/stdc++.h> #define N 200005 #define ll long long using namespace std; int main() {// freopen("in.txt", "r", stdin);ios::sync_with_stdio(false);int a, b, c, n;cin >> a >> b >> c >> n;if (a + b - c >= n || c >= n || a < c || b < c) cout << -1 << endl;else cout << n - (a + b - c) << endl;return 0; }B. Getting an A
題意
給一個(gè)長(zhǎng)度為N序列,每個(gè)數(shù)最大為5。為改變幾個(gè)數(shù)可以讓平均數(shù)為5(四舍五入)
因?yàn)榫缺籬ack
C. Candies
題意
一共有N個(gè)糖果,Vasya每次吃K個(gè),Petya吃剩下的%10 (向下取整),求在Vasya至少吃一半糖果的情況下最小的K
AC
// 二分 include <bits/stdc++.h> #define N 200005 #define ll long long using namespace std; bool solve(ll n, ll m) {ll sum_l = 0, sum_r = 0;while (n > 0) {if (n >= m)sum_l += m;elsesum_l += n;n -= m;if (n >= 10)sum_r += n / 10;n -= n / 10;}if (sum_l >= sum_r) return true;else return false; } int main() {// freopen("in.txt", "r", stdin);ios::sync_with_stdio(false);ll n;cin >> n;ll l = 1, r = n;while (l < r) {ll mid = (l + r) / 2;if (solve(n, mid))r = mid;elsel = mid + 1;}cout << l << endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的Codeforces Round #491 (Div.2)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: string常用操作
- 下一篇: Codeforces Round #49