Ice cream samples Gym - 101670G 滑动扫描

题目:题目链接

思路:比赛中读错了题,题目要求选一个连续区间,却读成了随便选取几个柜台,英语要好好学啊,读懂题就很简单了,扫一遍就出结果了

AC代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <vector>
 8 #include <string>
 9 #include <queue>
10 #include <map>
11 #include <set>
12
13 #define FRER() freopen("in.txt", "r", stdin);
14 #define INF 0x3f3f3f3f
15
16 using namespace std;
17
18 const int maxn = 1000000 + 5;
19
20 vector<int> stand[maxn << 1];
21
22 int brand[maxn], N, K;
23
24 void init() {
25     for(int i = 0; i < (N << 1); ++i)
26         stand[i].clear();
27     memset(brand, 0, sizeof(brand));
28 }
29
30 int solve() {
31     int st = 0, ed = 0, ans = INF, k = 0, now = 0;
32     while(ed < (N << 1)) {
33         for(int i = 0; i < stand[ed].size(); ++i) {
34             ++now;
35             if(brand[stand[ed][i]] == 0)
36                 ++k;
37             ++brand[stand[ed][i]];
38         }
39         ++ed;
40         while(k == K && st < ed) {
41             ans = min(ans, now);
42             for(int i = 0; i < stand[st].size(); ++i) {
43                 --now;
44                 --brand[stand[st][i]];
45                 if(brand[stand[st][i]] == 0)
46                     --k;
47             }
48             ++st;
49         }
50     }
51     return ans == INF ? -1 : ans;
52 }
53
54 int main()
55 {
56     //FRER()
57     while(~scanf("%d %d", &N, &K)) {
58         init();
59         int n, num;
60         for(int i = 0; i < N; ++i) {
61             scanf("%d", &n);
62             for(int j = 0; j < n; ++j) {
63                 scanf("%d", &num);
64                 stand[i].push_back(num);
65                 stand[i + N].push_back(num);
66             }
67         }
68         printf("%d\n", solve());
69     }
70     return 0;
71 }

原文地址:https://www.cnblogs.com/fan-jiaming/p/9833770.html

时间: 2024-10-11 18:28:51

Ice cream samples Gym - 101670G 滑动扫描的相关文章

Gym - 101670G Ice cream samples(CTU Open Contest 2017 尺取法)

题目: To encourage visitors active movement among the attractions, a circular path with ice cream stands was built in the park some time ago. A discount system common for all stands was also introduced. When a customer buys ice cream at some stand, he

Ice Cream Tower

2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output file: Standard Ouptut Time limit: 6 seconds Mr. Panda likes ice cream very much especially the ice cream tower. An ice cream tower consists of K ice cr

HackerRank Ice Cream Parlor

传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together have M dollars they want to spend on ice cream. The parlor offers N flavors, and they want to choose two flavors so that they end up spending the whol

codeforces 686A A. Free Ice Cream(水题)

题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using

【HackerRank】Ice Cream Parlor

Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N flavors available, they have to choose two distinct flavors whose cost equals M. Given a list of cost of N flavors, output the indices of two items wh

How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich

ShareThis - By Vikas Verma Bluetooth low energy (BLE) is a feature of Bluetooth 4.0 wireless radio technology, aimed at new, principally low-power and low-latency, applications for wireless devices within a short range. As I discussed in my previous

E. Sonya and Ice Cream(开拓思维)

E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Sonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that

CodeForces 804C Ice cream coloring

Ice cream coloring 题解: 这个题目中最关键的一句话是, 把任意一种类型的冰激凌所在的所有节点拿下来之后,这些节点是一个连通图(树). 所以就不会存在多个set+起来之后是一个新的完全图. 所以只要直接去做就好了. 对于每个节点来说,染色. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freope

The 2016 ACM-ICPC Asia China-Final Contest Gym - 101194D Ice Cream Tower

题意:熊猫先生想用一些冰淇淋球来做k层的冰淇淋,规定对于一个冰淇淋中的每一个冰淇淋球(最顶层除外),都大于等于上一层的冰淇淋球的两倍大小:现有n个冰淇淋球,问最多能做几个冰淇淋 思路:刚开始想的贪心,最后发现是不行的.比如对于 1 2 3 4 这种情况,1 后面是2还是3就没法用程序来进行抉择了.可以用二分的方法,枚举所有可能的冰淇淋个数x,然后再进行判断当前的冰淇淋球能否做成x个冰淇淋 1 #include <bits/stdc++.h> 2 using namespace std; 3 t