• codeforces 401 B Sereja and Contests【贪心】


    题意:给出最后的时间n,div 1必须和div2一起举行,并且div2的时间总是比div1大1

    给出Sereja(只能参加div2)参加过的k场比赛的时间,问他最少错过了多少场div2,最多错过了多少场div 2

    先扫描一遍单个的没有用过的时间,再扫一遍连续的两个没有用过的时间

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
    14 
    15 typedef long long LL;
    16 const int INF = (1<<30)-1;
    17 const int mod=1000000007;
    18 const int maxn=100005;
    19 
    20 int hash[maxn];
    21 
    22 int main(){
    23     int n,m;
    24     cin>>n>>m;
    25     memset(hash,0,sizeof(hash));
    26     
    27     
    28     while(m--){
    29         int x,u,v;
    30         cin>>x;
    31         if(x==1){
    32             cin>>u>>v;
    33             hash[u]=hash[v]=1;
    34         }
    35         if(x==2) {
    36             cin>>u;
    37             hash[u]=1;
    38         }        
    39     }
    40     
    41     int minn=0,maxx=0;
    42     
    43     for(int i=1;i<n;i++){
    44         if(hash[i]==0) maxx++;
    45     }
    46     
    47     
    48     for(int i=1;i<n-1;i++){
    49         if(hash[i]==0&&hash[i+1]==0) {
    50             minn++;
    51             hash[i]=1;
    52             hash[i+1]=1;
    53         }
    54     }
    55     
    56     printf("%d %d
    ",maxx-minn,maxx);
    57     return 0;
    58 }
    View Code

    读题读了好久的说啊-------------- gooooooooooooo

  • 相关阅读:
    禁止网页后退
    C# 数组排序
    SQL求往年的工资和
    手机的隐秘功能
    C#中的String类
    C#修饰符
    Application,Session,Cookie,ViewState和Cache区别
    css margin和padding的区别
    php常见的js正则表达式
    js 正则表达式基础篇
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4481951.html
Copyright © 2020-2023  润新知