Codeforces Gym101522 A. Ambiguous Dates (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
There are two popular formats for representing a date: day/month/year or month/day/year. For example, today can be represented as 15/8/2017 or 8/15/2017.
Sometimes (like on today), using one way or another should pose no confusion — it is immediately understood that the date is the 15th of August. On other days, however, the two representations may be interpreted as two different valid dates. For example, the 7th of August may be misinterpreted as the 8th of July, since both can be represented as 7/8/2017 (or 8/7/2017).
We say a date (D, M, Y) is ambiguous if D/M/Y and M/D/Y, when both interpreted in the day/month/year format, are different valid dates. For example, (7, 8, 2017) and (8, 7, 2017) are ambiguous, while (15, 8, 2017) and (10, 10, 2017) are not.
The total number of ambiguous dates in the Gregorian calendar system on any given year is equal to 12 × 11 = 132.
Now, suppose that in a hypothetical calendar system, there are M months, where the i-th month has D[i] days, numbered from 1 to D[i]. Assume that there are no leap years.
You are to carry out a calendar reform, by shuffling the array D[], and your target is to minimize the total number of ambiguous dates in a calendar year. Specifically, you want to find a permutation p[1], p[2], ..., p[M] of integers 1, 2, ..., M, such that the new calendar system, where the i-th month has D[p[i]] days, has the minimal number of ambiguous dates. Output that minimal number.
Input
The first line of input consists of a single integer M, the number of months in the hypothetical calendar system.
The second line of input consists of M integers D[1], D[2], ..., D[M], the original number of days in the i-th month.
For all test cases, 1 ≤ M ≤ 105, 1 ≤ D[i] ≤ 105.
Output
Output a single integer, the minimal number of ambiguous dates after the calendar reform.
Example
12
31 28 31 30 31 30 31 31 30 31 30 31
132
3
5 1 1
0
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
int a[N];
int main(){
int n;
ll ans;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
ans=;
for(int i=;i<=n;i++){
if(a[i]>n){if(n-i>)ans+=n-i;}
if(a[i]<n){if(a[i]-i>)ans+=a[i]-i;}
if(a[i]==n){if(n-i>)ans+=n-i;}
}
ans*=;
printf("%lld\n",ans);
}
return ;
}
Codeforces Gym101522 A. Ambiguous Dates (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)的更多相关文章
- Codeforces Gym101522 C.Cheering-字符串 (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
		
C.Cheering To boost contestants' performances in the 20th La Salle - Pui Ching Programming Challenge ...
 - Codeforces Gym101522 D.Distribution of Days-算日期 (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
		
D.Distribution of Days The Gregorian calendar is internationally the most widely used civil calendar ...
 - gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017
		
西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg A.水题,排序 #include<cstdio> #include<iostream> #includ ...
 - 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E
		
链接:http://codeforces.com/gym/101116 学弟写的,以后再补 #include <iostream> #include <algorithm> # ...
 - 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) J
		
链接:http://codeforces.com/gym/101116 题意:给出n个点,要求一个矩形框将(n/2)+1个点框住,要面积最小 解法:先根据x轴选出i->j之间的点,中间的点(包括 ...
 - 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) I
		
链接:http://codeforces.com/gym/101116 题意:选六个数,必须出现次数最多,且数字最小,如果出现7优先加入7 解法:排序,出现7优先加入7,最后再将6个数排序 #incl ...
 - 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) B
		
链接:http://codeforces.com/gym/101116 学弟做的,以后再补 #include <iostream> #include <stdio.h> #in ...
 - Codeforces Global Round 2  D. Frets On Fire (动态开点线段树,沙雕写法)
		
题目链接:D. Frets On Fire 思路:明明可以离散化+二分写,思路硬是歪到了线段树上,自闭了,真实弟弟,怪不得其他人过得那么快 只和查询的区间长度有关系,排完序如果相邻的两个点的差值小于等 ...
 - Codeforces Gym100735 I.Yet another A + B-Java大数 (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)
		
I.Yet another A + B You are given three numbers. Is there a way to replace variables A, B and C with ...
 
随机推荐
- oracle  事务  第一弹
			
一.事务概念 概念:在数据库中事务是工作的逻辑单元,一个事务是由一个或多个完成一组的相关行为的SQL语句组成,通过事务机制确保这一组SQL语句所作的操作要么完全成功执行,完成整个工作单元操作,要么一点 ...
 - IOS开发---菜鸟学习之路--(十九)-利用NSUserDefaults存储数据
			
利用NSUserDefaults的可以快速的进行本地数据存储,但是支持的格式有限, 至于支持什么格式大家可以再自行脑补 我这边直接讲如何使用 NSUserDefaults 分为两部分 一个是存数据 N ...
 - leetcode 【 Find Minimum in Rotated Sorted Array II 】python 实现
			
题目: Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? W ...
 - IOS开发学习笔记024-UIButton和UIImageView的区别
			
一.UIButton和UIImageView的区别 1. UIImageView 默认只能显示一张图片(默认会填充整个ImageView) 设置方法:image/setImage: UIButton ...
 - Python-S9-Day116——Flask框架相关
			
01 内容回顾 02 Flask框架:路由和视图(一) 03 Flask框架:路由和视图(二) 04 Flask框架:路由和视图(三) 05 Flask框架:路由和视图(四) 06 Flask框架:s ...
 - Mac 因误使用chmod -R 777 命令更改 /usr/bin 造成终端不能实用,提醒进程已结束的完美解决方案!
			
1.不用删除任何文件. 2.启动root用户权限 4.在用root用户登进去 5.在root用户中使用终端输入命令 chown root:wheel /usr/bin/login chmod u+s ...
 - python矩阵和向量的转置问题
			
numpy有很多方法进行转置,这里由于时间和精力限制(主要是我实在比较懒,有一个基本上一直能使的,就懒得看其他的了),其他方法我没研究,这里我总结的东西,如果有问题,欢迎各路大佬拍砖 一.创建矩阵: ...
 - ruby linux连接windows执行dos命令
			
在整个开发流程中,gitlab-runner-ci是搭建在linux下.web自动化是在windows下面进行的. 如果ci构建完版本.部署完后,需要触发启动自动化执行. 那么我们需要在部署完后在li ...
 - BZOJ-3231 [SDOI2008]递归数列
			
转成矩阵连乘后,矩阵快速幂加速解决. 一开始没把需要longlong的变量补全..而且没初始化2333 #include <cstdlib> #include <cstdio> ...
 - BZOJ3531 [Sdoi2014]旅行  【树剖 + 线段树】
			
题目 S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足 从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教.绝地教都是常见的信仰.为了方便,我们用 ...