CodeForces 297C Splitting the Uniqueness (脑补构造题)

news/2024/6/18 2:45:11

题意

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 ⌊ 2 n / 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,  s i ≥  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  a i =  i (do not care values of  b) i = 10... 19:  assign  b i =  i (do not care values of  a) i = 20... 29:  assign  b i = 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\n", a[n-1]); for (int i = 0; i < n-1; i ++) printf("%d ", b[i]); printf("%d\n", b[n-1]); return 0; } [/cpp]

转载于:https://www.cnblogs.com/AbandonZHANG/p/4114323.html


http://www.niftyadmin.cn/n/2556777.html

相关文章

设备用反线 不同设备用平行 这条法则要好好理解.

"设备用反线 不同设备用平行" 这条法则是组建网络的连线法则,但是要会理解. 一般的网卡还是按这个法则没有错,但是遇到笔记本的自适应网卡时,就要注意下. 为什么那? 记本电脑通常内置无线和有线网卡&#xff0c;虽然无线网络数据传输目前已经成为主流&#xff0c;但…

C#:iterator 迭代器/partial class 分布类/泛型

iterator 迭代器 写个最简单的迭代&#xff0c;&#xff08;迭代一个字符串数组&#xff09;&#xff1a; 1.实现接口中的方法&#xff1a; 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 usi…

学习:SQL数据库日志收缩(转)

declare data varchar(20) select data 数据库名 execute (execute sp_helpdb data ) execute ( BACKUP LOG data WITH TRUNCATE_ONLY ) execute ( DBCC SHRINKDATABASE( data ,10)) execute (execute sp_helpdb data ) 文章来源&#xff1a;http://bbs.winos.cn/v…

基本知识点罗列

1.dropdownlist的绑定 BLLAuction bll_getAuctionnew BLLAuction();this.ddlauctioncode.DataSource bll_getAuction.GetAuctionList();this.ddlauctioncode.DataTextField "Name";this.ddlauctioncode.DataValueField "code";this.ddlauctioncode.Data…

Administrator用户直接获取SYSTEM权限

来源&#xff1a; http://www.nsfocus.com 作者&#xff1a;"scz" < scznsfocus.com> 标题: MSDN系列(3)--Administrator用户直接获取SYSTEM权限 日期: 2003-06-21 21:51更新: --------------------------------------------------------------------------…

web developer tips (26):在 App_Code目录下同时放c#和VB.NET文件

原文地址&#xff1a;How to have C# and VB.NET files inside your App_Code directory 如果你利用App_Code目录来开发一个Asp.net web网站&#xff0c;有时候需要写用不同net语言的代码文件。例如&#xff0c;如果你想用在同一个web网站同时使用c#和VB.net http://www.watch-…

IE盒子模型和标准框元素模型

1、ie模型 2、w3c模型 3、box-sizing 4、*{box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box;} 记录一个重要的属性的box-sizing TODO&#xff1a;转载于:https://www.cnblogs.com/linksgo2011/p/3268624.html

火狐插件Firebug的使用

什么是Firebug 从事了数年的Web开发工作&#xff0c;越来越觉得现在对WEB开发有了更高的要求。要写出漂亮的HTML代码&#xff1b;要编写精致的CSS样式表展示每个页面模块&#xff1b;要调试javascript给页面增加一些更活泼的要素&#xff1b;要使用Ajax给用户带来更好的体验。一…