XMU 1611 刘备闯三国之卖草鞋 【贪心】
1611: 刘备闯三国之卖草鞋
Time Limit: 1000 MS Memory Limit: 64 MB
Submit: 90 Solved: 48
[Submit][Status][Web Board]Description
刘备(161年-223年6月10日),字玄德,东汉末年幽州涿郡涿县,西汉中山靖王刘胜的后代。刘备一生极具传奇色彩,早年颠沛流离、备尝艰辛最终却凭借自己的谋略终成一方霸主。那么在那个风云激荡的年代,刘备又是如何从一个卖草鞋的小人物一步一步成为蜀汉的开国皇帝呢?让我们一起拨开历史的迷雾,还原一个真实的刘备。
刘备小时候家境贫寒,与母亲靠卖草鞋、编织席子为生。当然,作为日后的王者,刘备卖起草鞋来当然是毫无含糊,所以生意兴隆。
每天、刘备都会收到许多个订单,这些订单要求次日完成。由于刘备编织草鞋忙的不可开交,所以统计次日要生产多少鞋子这个艰难的任务就要交刘备的小伙伴——也就是你了。当然,刘备本人精力也是有限的,他每天最多只能生产出1024双草鞋,多了他也没办法。
你的任务是,输出刘备次日要生产的鞋子的个数。
Input
第一行包含 一个整数n(1<=n<=100),表示有n个订单。
第二行包含n个整数a1,a2..an(ai<=100),表示每个订单的草鞋的个数。
Output
一个整数,表示刘备次日要生产的鞋子的个数。
Sample Input
3
5 4 1Sample Output
10HINT
Source
[Submit][Status][Web Board]
题目链接:
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1611
题目大意:
有N个订单,每个订单需要a[i]个草鞋。刘备最多生产1024个草鞋。问他共需要做多少草鞋。
题目思路:
【贪心】
审题审错了以为是背包WA了两次心痛。
直接统计草鞋和,如果超过1024就输出1024,否则输出和即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /**************************************************** 2 3 Author : Coolxxx 4 Copyright 2017 by Coolxxx. All rights reserved. 5 BLOG : http://blog.csdn.net/u010568270 6 7 ****************************************************/ 8 #include<bits/stdc++.h> 9 #pragma comment(linker,"/STACK:1024000000,1024000000") 10 #define abs(a) ((a)>0?(a):(-(a))) 11 #define lowbit(a) (a&(-a)) 12 #define sqr(a) ((a)*(a)) 13 #define mem(a,b) memset(a,b,sizeof(a)) 14 const double EPS=1e-8; 15 const int J=10; 16 const int MOD=100000007; 17 const int MAX=0x7f7f7f7f; 18 const double PI=3.14159265358979323; 19 const int N=104; 20 const int M=1204; 21 using namespace std; 22 typedef long long LL; 23 double anss; 24 LL aans; 25 int cas,cass; 26 int n,m,lll,ans; 27 int a[N]; 28 int main() 29 { 30 #ifndef ONLINE_JUDGE 31 // freopen("1.txt","r",stdin); 32 // freopen("2.txt","w",stdout); 33 #endif 34 int i,j,k; 35 int x,y,z; 36 // for(scanf("%d",&cass);cass;cass--) 37 // for(scanf("%d",&cas),cass=1;cass<=cas;cass++) 38 // while(~scanf("%s",s)) 39 while(~scanf("%d",&n)) 40 { 41 m=1024;ans=0; 42 for(i=1;i<=n;i++) 43 { 44 scanf("%d",&a[i]); 45 ans+=a[i]; 46 } 47 if(ans>m)printf("%d\n",m); 48 else printf("%d\n",ans); 49 } 50 return 0; 51 } 52 /* 53 // 54 55 // 56 */