Codeforces Round #509 (Div. 2) C. Coffee Break ###K ###K //K

题目链接:https://codeforces.ml/contest/1041/problem/C

题意:给定n个不同的数, 代表喝咖啡的时间,每次喝咖啡的间隔必须为d秒  每天只有m秒能喝,问最少多少天喝完

思路:考虑直接模拟,从1开始 用上set的二分搜索,每次找上一个数+d+1的位置

找到满足的就删去 时间复杂度o(nlogn)

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define pb push_back
 5 const int maxn =2e5+10;
 6 const int mod=1e9+7;
 7 map<int,int>mp;
 8 int ans[maxn];
 9 
10 
11 
12 int main()
13 {
14     ios::sync_with_stdio(false);
15     cin.tie(0);
16     int n,m,d;
17     cin>>n>>m>>d;
18     set<int>s;
19     for(int i=1;i<=n;i++)
20     {
21         int x;
22         cin>>x;
23         mp[x]=i;
24         s.insert(x);
25     }
26     d++;
27     int day=1;
28     int now=1;
29     set<int>::iterator it;
30     while(s.size())
31     {
32         it=s.lower_bound(now);
33         if(it==s.end())
34         {
35             now=1;
36             day++;
37         }
38         else
39         {
40             ans[mp[*it]]=day;
41             s.erase(*it);// +不+ *都可
42             now=*it+d;
43         }
44     }
45     cout<<day<<'\n';
46     for(int i=1;i<=n;i++)
47     {
48         cout<<ans[i]<<" ";
49     }
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 }
View Code

 

posted @ 2020-09-22 20:49  canwinfor  阅读(142)  评论(0)    收藏  举报