UESTC 1263 The Desire of Asuna (贪心)
来源:互联网 发布:数控车螺纹m24x1.5编程 编辑:程序博客网 时间:2024/04/28 11:16
题目链接:http://acm.uestc.edu.cn/#/problem/show/1263
思路:贪心的思想,排序,然后优先拆环数少的链子,然后查看是否能连接完成就行了。
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1010000#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define mod 1000000007using namespace std;int a[MAXN];int main(){int n,i;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);int cnt=n;int ans=0;for(i=0;i<n;i++){if(cnt-a[i]-1<1){ans+=cnt-1;break;}else{ ans+=a[i];cnt=cnt-a[i]-1;}}printf("%d\n",ans);}return 0;}
0 0
- UESTC--1263--The Desire of Asuna(贪心)
- UESTC 1263 The Desire of Asuna (贪心)
- UESTC 1263 The Desire of Asuna 贪心法&&构造法
- UESTC 1263-The Desire of Asuna
- UESTC - 1263:The Desire of Asuna【思维】
- CDOJ 1263 The Desire of Asuna 贪心
- uestc The Desire of Asuna 1263 (递推模拟)
- UESTC 1817 Complete Building the Houses 贪心
- Shortest path of the king(贪心)
- B. Game of the Rows(贪心)
- UESTC 1817——Complete Building the Houses 贪心
- UESTC 86 Divide(贪心+二进制)
- UESTC 929Post office(贪心)
- (CCPC F题)UESTC 1220 The Battle of Guandu (最短路)
- uestc oj 1869 Everyone out of the Pool
- uestc oj 1269 Children of the Candy Corn
- uva11292 The Dragon of Loowater (排序+贪心)
- UVa 11292 The Dragon of Loowater (贪心)
- 【转】将Oracle中的表结构导出到word
- next数组介绍
- LeetCode Gray Code
- Mysql函数大全
- POJ3087 Shuffle'm Up
- UESTC 1263 The Desire of Asuna (贪心)
- 基于空间金字塔池化的卷积神经网络物体检测
- maven构建spring4 mvc+spring4 websocket应用
- 用adt-bundle-windows 搭建Android开发环境
- 欢迎使用CSDN-markdown编辑器
- 如何在Qt工程中正确地引用用户自定义控件
- php实现选择排序
- 高性能c语言编码
- log4j2一些简单应用