zoukankan      html  css  js  c++  java
  • CodeForces 297C Splitting the Uniqueness (脑补构造题)

    题意

    Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指可以删掉数后再判断。

    思路

    略神的数学构造题。。。 官方题解: An equivalent definition for almost unique, is arrays with at least ⌊ 2n / 3⌋ different elements. The idea is to split s into three parts. In the first part, we give uniqueness to a. In the second part, we give uniqueness to b. In the third part, we give uniqueness to both. Lets assume s is sorted. Since s is an unique array, si ≥ i for all i (0-based). The image below will give some intuition on how to split it. ais red, b is blue, the length of the bar represent the magnitude of the number. In the first and second part, we do not care about the array that we are not giving uniqueness to.  We will make an example with n = 30. i = 0... 9:  assign ai = i (do not care values of b) i = 10... 19:  assign bi = i (do not care values of a) i = 20... 29:  assign bi = 29 - ia takes the remains. From i = 20, a will have strictly increasing values starting from at least 11.  

    代码

      [cpp] #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <set> #include <stack> #include <queue> #define MID(x,y) ((x+y)/2) #define MEM(a,b) memset(a,b,sizeof(a)) #define REP(i, begin, end) for (int i = begin; i <= end; i ++) using namespace std; typedef long long LL; struct num{ int value; int id; num(){} num(int _id, int _value){id = _id; value = _value;} }; bool cmp(num n1, num n2){ return n1.value < n2.value; } typedef vector <num> VI; VI v; int a[100005], b[100005]; int main(){ //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); int n; scanf("%d", &n); REP(i, 0, n-1){ int tmp; scanf("%d", &tmp); v.push_back(num(i, tmp)); } sort(v.begin(), v.end(), cmp); int d = (int)ceil((double)n/3); for (int i = 0; i < min(n, d); i ++){ a[v[i].id] = i; b[v[i].id] = v[i].value - a[v[i].id]; } for (int i = d; i < min(n, d*2); i ++){ b[v[i].id] = i; a[v[i].id] = v[i].value - b[v[i].id]; } for (int i = 2*d; i < n; i ++){ b[v[i].id] = n - 1 - i; a[v[i].id] = v[i].value - b[v[i].id]; } puts("YES"); for (int i = 0; i < n-1; i ++) printf("%d ", a[i]); printf("%d ", a[n-1]); for (int i = 0; i < n-1; i ++) printf("%d ", b[i]); printf("%d ", b[n-1]); return 0; } [/cpp]
  • 相关阅读:
    网站服务架构
    10年工作经验老程序员推荐的7个开发类工具
    极限挑战—C#+ODP 100万条数据导入Oracle数据库仅用不到1秒
    SQL SERVER发布与订阅
    C#开发可以可视化操作的windows服务
    highcharts图表中级入门:非histock图表的highcharts图表如何让图表产生滚动条
    MS Chart Control 學習手記(二)
    MsChart,饼状图
    c#中如何退出程序后自动重新启动程序
    2016 系统设计第一期 (档案一)MVC 控制器接收表单数据
  • 原文地址:https://www.cnblogs.com/AbandonZHANG/p/4114108.html
Copyright © 2011-2022 走看看