Codeforces Round #491 (Div.2)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #491 (Div.2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
get
- 被精度坑死了(B,C).遇到精度問題看能不能轉化為整數,不行的話就用eps判斷
A. If at first you don’t succeed…
題意
有兩個聚會,A個人去第一個聚會,B個人去第二個聚會,C個人兩個都去了,一共有N個人,至少有一個人一個聚會也沒有去,問一共有幾個人沒有去聚會,如果無解輸出-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
題意
給一個長度為N序列,每個數最大為5。為改變幾個數可以讓平均數為5(四舍五入)
因為精度被hack
C. Candies
題意
一共有N個糖果,Vasya每次吃K個,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; }總結
以上是生活随笔為你收集整理的Codeforces Round #491 (Div.2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: string常用操作
- 下一篇: Codeforces Round #49