CodeForces 990Bミクロの世界(思考、STL)

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

 

 

 

 

質問の意味:

N -細菌、細菌は、各Aの大きさであり、I A、I、細菌の大きさがあれば、定数kによって今、iは細菌j個のAのサイズよりも大きいJ、およびA I <A = J + K、iはその後細菌があってもよいです細菌jを食べて、そして最終的には上のままにすることができますどのように多くの細菌尋ねました。

実践:

そしてその後、細菌の数と同じ大きさを記録することは、それらが要件を満たしている場合に比較する細胞の数を減算することにより、要件を満たすために並べ替え、開始時刻の比較細胞小さなセルよりも小さいセルに設定されたマップ

 

 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\n",num);
50     return 0;
51 }

 

 

 

 

 

 

おすすめ

転載: www.cnblogs.com/jiamian/p/11860993.html