zoukankan      html  css  js  c++  java
  • CodeForces 990B Micro-World(思维、STL)

    http://codeforces.com/problemset/problem/990/B

     

    题意:

    有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且ai<=aj+k,那么细菌i就可以吃掉细菌j,问最后可以剩于多少个细菌。

    做法:

    用map记录相同尺寸细菌的个数,然后用set进行去重排序,从次小的细胞开始比较比该细胞小一点的细胞是否符合要求,如果符合要求,减去被比较的细胞的个数

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 #define Bug cout<<"---------------------"<<endl
    16 const int mod=1e9+7;
    17 const int maxn=2e5+10;
    18 using namespace std;
    19 
    20 map<int,int> mp;
    21 set<int> st;
    22 
    23 int main()
    24 {
    25     int n,k;
    26     scanf("%d %d",&n,&k);
    27     for(int i=0;i<n;i++)
    28     {
    29         int t;
    30         scanf("%d",&t);
    31         mp[t]++;
    32         st.insert(t);
    33     }
    34     int num=n;
    35     int pre;
    36     for(set<int>::iterator it=st.begin();it!=st.end();it++)
    37     {
    38         if(it==st.begin())
    39         {
    40             pre=*it;
    41             continue;
    42         }    
    43         if(*it>pre&&*it<=pre+k)
    44         {
    45             num-=mp[pre];
    46         }
    47         pre=*it;
    48     }
    49     printf("%d
    ",num);
    50     return 0;
    51 }
  • 相关阅读:
    行为型模式之 命令模式
    结构型模式之 代理模式
    oop编程思想
    2013应届毕业生各大IT公司待遇整理汇总篇(转)
    python定义class
    python——博客园首页信息提取与分析(转载有改动)
    深入浅出TCP/IP协议
    python基础之socket
    python基础
    c++stl之stack
  • 原文地址:https://www.cnblogs.com/jiamian/p/11860993.html
Copyright © 2011-2022 走看看