[CF 297 C] Splitting the Uniqueness
2018-02-28 19:08
447 查看
题目描述:
给出 一个 序列 A求出 另外两个序列 B C
使得 A[i]=B[i]+C[i] 且 B 和 C 两个序列 每个去除相同元素后最起码剩下 (2/3)*n 个元素
题目分析:
构造题目第一次做.首先把序列 3分
将 A 排序
对于前 1/3 B[i]=i-1 C[i]=A[i]-B[i]
对于1/3–2/3 C[i]=i-1 B[i]=A[i]-C[i]
对于 2/3–n C[i]=n-i B[i]=A[i]-C[i]
很明显 前1/3的B与后1/3的B 肯定不同
对于C同理
题目链接
Splitting the UniquenessAC 代码:
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> const int maxm=1e6+100; struct node{ int val,id; }; node a[maxm]; bool comp(node x,node y) { return x.val<y.val; } bool compid(node x,node y) { return x.id<y.id; } int n; node b[maxm],c[maxm]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i].val),a[i].id=i; std::sort(a+1,a+n+1,comp); double x=(double)n/3.0; int T=(int)ceil(x); for(int i=1;i<=T;i++) { b[i].id=c[i].id=a[i].id; b[i].val=i-1,c[i].val=a[i].val-b[i].val; } for(int i=T+1;i<=n-T;i++) { b[i].id=c[i].id=a[i].id; c[i].val=i-1,b[i].val=a[i].val-c[i].val; } for(int i=n-T+1;i<=n;i++) { b[i].id=c[i].id=a[i].id; c[i].val=n-i,b[i].val=a[i].val-c[i].val; } std::sort(b+1,b+n+1,compid); std::sort(c+1,c+n+1,compid); printf("YES\n"); for(int i=1;i<=n;i++) printf("%d ",b[i].val); puts(""); for(int i=1;i<=n;i++) printf("%d ",c[i].val); return 0; }
相关文章推荐
- 【CodeForces】297C - Splitting the Uniqueness(构造)
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
- Codeforces 297C. Splitting the Uniqueness
- codeforces -297c Splitting the Uniqueness【构造】
- 【CodeForces 297C】Splitting the Uniqueness
- [Codeforces297C]Splitting the Uniqueness(构造)
- codeforces 297C Splitting the Uniqueness
- 【Codeforces】-297C-Splitting the Uniqueness(构造)
- CF - 409 - A. The Great Game(IQ)
- cf——A. Down the Hatch!
- The Uniqueness of Software Engineering: The Dual Formalizations
- CF 321C(Ciel the Commander-点分治)
- CF 319C - Kalila and Dimna in the Logging Industry 斜率优化DP
- 【20.73%】【CF 716B】Complete the Word
- CF 869 B. The Eternal Immortality【数学】
- CF 451 C Predict Outcome of the Game(数学题)
- CF 312C. The Closest Pair 简单构造
- CF 812B Sagheer, the Hausmeister
- 洛谷P3145 [USACO16OPEN]分割田地Splitting the Field