日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #491 (Div.2)

發(fā)布時(shí)間:2024/4/18 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

// 轉(zhuǎn)化為整數(shù)處理 #include <bits/stdc++.h> #define N 200005 using namespace std; long long a[N], b[N]; vector<int> v; // pair<int,int> sum[N]; int main() {// freopen("in.txt", "r", stdin);ios::sync_with_stdio(false);int n;cin >> n;vector<int> v(n);for (int i = 0; i < n; i++) {cin >> v[i];}int sum = accumulate(v.begin(), v.end(), 0);int tar = (5 * n - n / 2);sort(v.begin(), v.end());if (sum >= tar) {cout << 0 << endl;return 0;}int ans = 0;for (auto it : v) {sum += (5 - it);ans++;if (sum >= tar) break;}cout << ans << endl;return 0; } #include <bits/stdc++.h> #define N 200005 using namespace std; long long a[N], b[N]; vector<int> v; // pair<int,int> sum[N]; int main() {// freopen("in.txt", "r", stdin);ios::sync_with_stdio(false);int n;cin >> n;vector<int> v(n);for (int i = 0; i < n; i++) {cin >> v[i];}sort(v.begin(), v.end());int sum = accumulate(v.begin(), v.end(), 0);if (sum * 1.0 / n >= 4.5) {cout << 0 << endl;return 0;}int ans = 0;for (int i = 0; i < n; i++) {sum += 5 - v[i];ans++;if (sum * 1.0 / n >= 4.5) break;// cout << i << " " << sum << endl;}cout << ans << endl;return 0; } // 精度錯(cuò)誤 #include <bits/stdc++.h> #define N 200005 using namespace std; long long a[N], b[N]; double eps = 1e-5; vector<int> v; // pair<int,int> sum[N]; int main() {// freopen("in.txt", "r", stdin);ios::sync_with_stdio(false);int n;cin >> n;vector<int> v(n);for (int i = 0; i < n; i++) {cin >> v[i];}sort(v.begin(), v.end());int sum = accumulate(v.begin(), v.end(), 0);double now = sum * 1.0 / n;if ( now >= 4.5) {cout << 0 << endl;return 0;}int ans = 0;for (int i = 0; i < n; i++) {// 含有小數(shù)的運(yùn)算,容易出現(xiàn)精度問題now += (5 - v[i]) * 1.0 / n;ans++;if (now >= 4.5 || fabs(now - 4.5) <= eps) break;// cout << i << " " << sum << endl;}cout << ans << endl;return 0; }

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。