Gym101522A Gym101522C Gym101522D
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 ;
}
Gym101522A Gym101522C Gym101522D的更多相关文章
随机推荐
- lesson - 1 笔记 网络连接 /putty 密钥登陆
---笔记 一.网络连接配置 1. 查看电脑ip 地址: ifconfig -a 2. 自动获取ip 地址: dhclient 默认BOOTPROTO=dhcp 和真机同一网段 3. 手动配置 ...
- raspberrypi 3代B 配置摄像头
raspberrypi 3代B 配置摄像头 硬件环境: 树莓派3B (element 14版) 树莓派3夜视摄像头800万像素(element 14版) 金士顿 64GB TF Class 10 UH ...
- 中文代码示例之Vuejs入门教程(一)
原址: https://zhuanlan.zhihu.com/p/30917346 为了检验中文命名在主流框架中的支持程度, 在vuejs官方入门教程第一部分的示例代码中尽量使用了中文命名. 所有演示 ...
- VS2017 调试不能命中断点问题
去掉勾
- Effective Java 第三版——15. 使类和成员的可访问性最小化
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- Python学习_07_错误、异常
地毯式地过语法终于快要结束了... Python中的常见异常 1.NameError:尝试访问一个未初始化的变量 2. ZeroDivisionError:除数为0 3. SyntaxError:Py ...
- SecureCRT 历史版本下载
最近在使用SecureCRT时,存在网络卡顿现象,然而.同事的SecureCRT工具却一点都不卡,我的SecureCRT是比较老的版本6,同事使用的是版本7,所以就更换下自己的SecureCRT版本. ...
- Wechat 微信端调用“微信支付接口”的正确方式
微信端的项目中,比如微信商城之类的,肯定会涉及到微信支付这一块: 下面直接上详细的代码: var data = {--}; // 调用微信支付需要的数据 function onBridgeReady( ...
- mysql如何执行关联查询与优化
mysql如何执行关联查询与优化 一.前言 在数据库中执行查询(select)在我们工作中是非常常见的,工作中离不开CRUD,在执行查询(select)时,多表关联也非常常见,我们用的也比较多,那么m ...
- 第一篇:Win10系统搭建Python+Django+Nginx+MySQL 开发环境详解(完美版)
Win10+Python+Django+Nginx+MySQL 开发环境搭建详解 PaulTsao 说明:本文由作者原创,仅供内部参考学习与交流,转载引用请注明出处,用于商业目的请联系作者本人. Wi ...