牛客网Wannafly挑战赛15 B车辆安排(模拟)AND C 出队(规律)
生活随笔
收集整理的這篇文章主要介紹了
牛客网Wannafly挑战赛15 B车辆安排(模拟)AND C 出队(规律)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
傳送門(mén) :B題:點(diǎn)我
C題:?點(diǎn)我
題目描述
有n個(gè)隊(duì)伍,每個(gè)隊(duì)伍的人數(shù)小于等于5,每輛車(chē)最多坐5個(gè)人,要求一個(gè)隊(duì)伍的人都在一輛車(chē)上,求最少的車(chē)數(shù)
輸入描述:
第一行n
第二行n個(gè)數(shù),表示每個(gè)隊(duì)伍的人數(shù)
輸出描述:
輸出最少車(chē)數(shù)
示例1輸入
3 3 4 5輸出
3備注:
n≤1e5每個(gè)數(shù)小于等于5思路:大力模擬。5自己一車(chē),4跟1一車(chē),然后3跟2一車(chē),2的時(shí)候分情況考慮,如果2是偶數(shù),那么2+2+1或者2+2,如果2是奇數(shù),那么分成偶數(shù)+1,最后一個(gè)2,可以2+1+1+1,或者2+1+1或者2+1或者2,最后處理1
代碼:(因?yàn)樘L(zhǎng)了就折疊了,然后最后附上了一些測(cè)試數(shù)據(jù)) #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <algorithm> #include <sstream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <utility> #include <bitset>using namespace std; #define LL long long #define pb push_back #define mk make_pair #define pill pair<int, int> #define mst(a, b) memset(a, b, sizeof a) #define REP(i, x, n) for(int i = x; i <= n; ++i) int main(){int n;scanf("%d",&n);int a[6] = {};for(int i = 0 ; i < n ; i++){int x;scanf("%d",&x);a[x]++;}int sum = a[5];if(a[1] >= a[4]){sum += a[4];a[1] -= a[4];}else{sum += a[4];a[1] = 0;}if(a[2] >= a[3]){sum += a[3];a[2] -= a[3];}//如果2 比 3多 else{sum += a[2];a[3] -= a[2];a[2] = 0;int t = 2 * a[3];//a[3]可以帶走多少a[1]if(a[1] >= t){sum += a[3];a[1] -= t;}else{sum += a[3];a[1] = 0;}}if(a[2] >= 0){int d1,d2;if(a[2] % 2 == 0){d1 = a[2] / 2;if(a[1] >= d1){sum += d1;a[1] -= d1;}else{sum += d1;a[1] = 0;}}else{d1 = a[2] / 2;d2 = 1;sum += 1;//無(wú)論怎么樣多出來(lái)這一個(gè)2肯定要一輛車(chē)if(a[1] >= d1){sum += d1;a[1] -= d1;}else{sum += d1;a[1] = 0;}if(a[1] >= 3){a[1] -= 3;}else{a[1] = 0;}}}if(a[1] != 0){sum += (a[1]%5 == 0 ? a[1]/5 : a[1]/5 + 1);}printf("%d\n",sum); } /* 9 1 1 2 2 2 3 3 3 4 54 1 1 1 1 16 1 2 3 4 5 2 47 2 2 2 2 1 1 1 36 2 2 2 2 1 1 27 1 2 2 2 2 2 3 35 4 4 4 4 1 45 4 4 4 2 1 46 4 4 4 2 1 3 47 1 2 2 2 3 4 5 46 1 1 1 3 4 5 3 */ View Code
?
C題 出隊(duì)
是個(gè)CF原題額,就是換了個(gè)題面。http://codeforces.com/contest/950/problem/D
題目描述
約瑟夫問(wèn)題(https://baike.baidu.com/item/約瑟夫問(wèn)題),n個(gè)人,1 2報(bào)數(shù) 1出隊(duì)( 就是體育課的時(shí)候1 2報(bào)數(shù) 1出隊(duì),2留下),q次詢問(wèn),每次求第x個(gè)人是第幾個(gè)出隊(duì)的輸入描述:
第一行兩個(gè)數(shù)n,q接下來(lái)q行,每行一個(gè)數(shù)x,表示詢問(wèn)
輸出描述:
一行輸出一個(gè)詢問(wèn)的答案 示例1輸入
4 3 2 3 4輸出
3 2 4說(shuō)明
1 2 3 4圍成一圈,第一輪:1 2報(bào)數(shù),1出隊(duì),2留下,3出隊(duì),4留下,第二輪,2出隊(duì),4留下備注:
q≤500000n和x≤1e18
代碼: #include<stdio.h> typedef long long ll; int main() {ll n,m,x;scanf("%lld%lld",&n,&m);while(m--){scanf("%lld",&x);while(x%2==0)x=n+x/2;printf("%lld\n",(x+1)/2);}return 0; }
轉(zhuǎn)載于:https://www.cnblogs.com/Esquecer/p/9026710.html
總結(jié)
以上是生活随笔為你收集整理的牛客网Wannafly挑战赛15 B车辆安排(模拟)AND C 出队(规律)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 11.06
- 下一篇: div水平垂直居中的六种方法