第八屆“圖靈杯”NEUQ-ACM程式設計競賽個人賽(同步賽)A. 切蛋糕
阿新 • • 發佈:2021-02-01
技術標籤:數學——雜項
連結
https://ac.nowcoder.com/acm/contest/11746/A
題意
每次只能將一塊蛋糕平均分成兩塊,蛋糕最小為
1
2
15
\frac 1 {2^{15}}
2151
可以將幾塊蛋糕打包分給某人,現在要分給
k
k
k 個人,要求每個人分到的蛋糕與
1
k
\frac 1 k
k1 的差的絕對值不大於
1
2
10
\frac 1 {2^{10}}
2101
切蛋糕為一次操作,打包為
1
1
1 操作,求操作次數不超過
6000
6000
6000 次的方案並輸出
思路
將蛋糕切成 1024 1024 1024 塊,等分給 k k k 個人,每個人分到的蛋糕滿足以下式子
- ∣ 1 k − ⌊ 1024 k ⌋ 1024 ∣ ≤ 1 1024 |\frac{1}{k}-\frac{\lfloor \frac {1024} {k} \rfloor}{1024}|\le\frac{1}{1024} ∣k1−1024⌊k1024⌋∣≤10241
- ∣ 1 k − ⌈ 1024 k ⌉ 1024 ∣ ≤ 1 1024 |\frac{1}{k}-\frac{\lceil \frac {1024} {k} \rceil}{1024}|\le\frac{1}{1024} ∣k1−1024⌈k1024⌉∣≤10241
程式碼
#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int > PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
//head
int t,cnt=0;
void solve(int x) {
if(x+1>10) return;
cout<<1<<' '<<x<<'\n';
solve(x+1);
solve(x+1);
}
int main() {
#ifdef DEBUG
freopen("E:/OneDrive/IO/in.txt","r",stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int k;
cin>>k;
cout<<1023+k<<'\n';
solve(0);
int a=1024%k,b=1024/k;
for(int i=1;i<=a;i++) {
cout<<2<<' '<<b+1<<' ';
for(int j=1;j<=b+1;j++) cout<<10<<" \n"[j==b+1];
}
for(int i=1;i<=k-a;i++) {
cout<<2<<' '<<b<<' ';
for(int j=1;j<=b;j++) cout<<10<<" \n"[j==b];
}
return 0;
}