zoukankan      html  css  js  c++  java
  • 九度 1377 缓变序列

    http://ac.jobdu.com/problem.php?id=1377

     首先庆祝昨天晚上没头疼~~~

    WA了无数次,找不到错误,两天之后双重写了一遍,一次就神奇的AC了。。

    从小往大放,因为,对于最小的数来说,肯定后面要放比它大1的数,依次类推,贪心是可行的。

     1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #define INF 0x7fffffff
    4 int N;
    5 int num_array[10005];
    6 void init()
    7 {
    8 int i;
    9 for(i=0;i<=10000;i++)
    10 num_array[i]=0;
    11 }
    12 int main()
    13 {
    14 while(scanf("%d",&N)!=EOF){
    15 int i;
    16 int temp;
    17 int num=0;
    18 int min_num=INF;
    19 init();
    20 bool flag=true;
    21 for(i=0;i<N;i++){
    22 scanf("%d",&temp);
    23 if(num_array[temp]==0)
    24 num++;
    25 num_array[temp]++;
    26 if(temp<min_num)
    27 min_num=temp;
    28 }
    29 int cur_num=min_num;
    30 if(num%2!=0){
    31 printf("NO\n");
    32 continue;
    33 }
    34 if(num==2){
    35 if(cur_num+1<=10000&&num_array[cur_num]==num_array[cur_num+1]){
    36 printf("YES\n");
    37 }else{
    38 printf("NO\n");
    39 }
    40 continue;
    41 }
    42 if(num==1){
    43 printf("NO\n");
    44 continue;
    45 }
    46 cur_num=min_num;
    47 for(i=1;i<=num-2;i++){
    48 if(cur_num+1<=10000&&num_array[cur_num+1]>num_array[cur_num]){
    49 num_array[cur_num+1]-=num_array[cur_num];
    50 cur_num++;
    51 }else{
    52 flag=false;
    53 break;
    54 }
    55 }
    56 if(!flag){
    57 printf("NO\n");
    58 }else if(cur_num+1<=10000&&num_array[cur_num+1]==num_array[cur_num]){
    59 printf("YES\n");
    60 }else{
    61 printf("NO\n");
    62 }
    63 }
    64 }



  • 相关阅读:
    shell script入门
    perl环境配置以及Eclipse安装perl开发插件
    python注释
    Python中的sorted函数以及operator.itemgetter函数
    python 字典items和iteritems
    Python 字典(Dictionary) get()方法
    python numpy sum函数用法
    python numpy argsort函数用法
    python tile函数用法
    Shell之date用法
  • 原文地址:https://www.cnblogs.com/yangce/p/2340829.html
Copyright © 2011-2022 走看看