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的更多相关文章
随机推荐
- 二叉树Binary_Tree(1):二叉树及其数组实现
定义 二叉树: 二叉树是一种特殊的树.二叉树的特点是每个结点最多有两个儿子,左边的叫做左儿子,右边的叫做右儿子,或者说每个结点最多有两棵子树.更加严格的递归定义是:二叉树要么为空,要么由根结点.左子树 ...
- C# VS2010结合SQL Server 2008数据库编程实现方法
SQL Server 数据库在C#编程中经常用到,如何实现在具体项目中数据库和具体应用的结合是我们经常遇到的问题,我们这次主要针对如何使用SQL Server 数据库展开,下面是具体的操作以及简单的代 ...
- C 函数参数 char **s与char *s[]
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/126 先来看一个小例子 : 编写函数遍历一个整型数组的元素,数组 ...
- 尝试在条件“$(_DeviceSdkVersion) >= 21”中对计算结果为“”而不是数字的“$(_DeviceSdkVersion)
晚上搞xamarin ,运行xamarin项目好好的,不知道怎么回事,一次运行xamarin android项目的时候,部署失败,以前也是遇到这样的错误. 尝试在条件"$(_DeviceSd ...
- 树链剖分X2
1.ZJOI树的统计 板子题 因为初始化没打改了几个小时 改到双腿软着出的机房(身体素质感人 #include<iostream> #include<cstdio> #incl ...
- 在海航云中部署 keepalived
**本文属自我学习,不适合转载** 1. 准备工作 1.1 网络方面的准备工作 1.1.1 创建安全组 注意这里要添加 vrrp 协议支持,否则 keepalived 将无法正常工作. 1.1.2 创 ...
- Golang中的坑二
Golang中的坑二 for ...range 最近两周用Golang做项目,编写web服务,两周时间写了大概五千行代码(业务代码加单元测试用例代码).用Go的感觉很爽,编码效率高,运行效率也不错,用 ...
- K:java中序列化的两种方式—Serializable或Externalizable
在java中,对一个对象进行序列化操作,其有如下两种方式: 第一种: 通过实现java.io.Serializable接口,该接口是一个标志接口,其没有任何抽象方法需要进行重写,实现了Serializ ...
- SQLServer LinkServer 链接服务器
Linked Server简介 我们日常使用SQL Server数据库时,经常遇到需要在实例Instance01中跨实例访问Instance02中的数据.例如在做数据迁移时,如下语句: insert ...
- 微信小程序入门指南
本文同步发布在 https://www.cssge.com 因为下个项目需要用微信小程序来开发,所以就找了小程序开发文档来研究.下面记录一下微信小程序的主要开发流程和语法. 账号注册 开发小程序的第一 ...