USACO 1.3.3

ExpandedBlockStart.gif View Code 
 1  /*
 2  ID:wconvey
 3  PROG:barn1
 4  LANG:C++
 5 
 6  */
 7 #include<iostream>
 8 #include<cstdio>
 9 #include<algorithm>
10  using  namespace std;
11  struct mode
12 {
13      int a;
14      bool flag;
15 }arr[ 210];
16  struct node
17 {
18      int a;
19      int no;
20 }b[ 210];
21  int cmp1(mode x,mode y)
22 {
23      return x.a<y.a;
24 }
25  int cmp(node x,node y)
26 {
27      return x.a>y.a;
28 }
29  int main()
30 {
31     freopen( " barn1.in ", " r ",stdin);
32     freopen( " barn1.out ", " w ",stdout);
33      int m,s,c;
34     scanf( " %d %d %d ",&m,&s,&c);
35      for( int i= 1;i<=c;i++)
36     {
37         scanf( " %d ",&arr[i].a);
38         arr[i].flag= false;
39     }
40     sort(arr+ 1,arr+ 1+c,cmp1);
41      for( int i= 1;i<c;i++)
42     {
43         b[i].a=arr[i+ 1].a-arr[i].a;
44         b[i].no=i;
45     }
46     sort(b+ 1,b+ 1+c- 1,cmp);
47      /* for(int i=1;i<c;i++)
48          printf("%d    %d***\n",b[i].a,b[i].no); */
49      for( int i= 1;i<m;i++)
50     {
51         arr[b[i].no].flag= true;
52          // printf("%d*******\n",b[i].no);
53          
54     }
55      int ans= 0;
56      int start=arr[ 1].a,end;
57      for( int i= 1;i<=c;i++)
58     {
59          if(arr[i].flag== true)
60         {
61              // printf("%d  *\n",i);
62              end=arr[i].a;
63             ans+=end-start+ 1;
64             start=arr[i+ 1].a;
65         }
66     }
67     ans+=arr[c].a-start+ 1;
68     printf( " %d\n ",ans);
69      // system("pause");
70       return  0;
71 
72

转载于:https://www.cnblogs.com/wconvey/archive/2012/05/27/2520633.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值