博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gym - 101670G Ice cream samples(CTU Open Contest 2017 尺取法)
阅读量:4497 次
发布时间:2019-06-08

本文共 3314 字,大约阅读时间需要 11 分钟。

题目:

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 is automatically granted a discount for one day at the next stand on the path. When visitors start at any stand and follow systematically the discount directions to the next stands, they eventually traverse the whole circular path and return back to the stand they started at.

Ice creams of various brands are sold at the stands. Additionally, each stand sells a nice sample box which contains small samples of popular ice cream brands. The number of samples in the box depends on the stand and various stands may put different brands into their sample boxes. Each box contains samples of one or more brands. A brand may be represented by one or more samples in the box, or it may be completely missing. Each stand sells only one type of sample box (the brands of the samples in the box are always the same for that particular stand).

Quido and Hugo are going to exploit the discount system for their own benefit. They decided to start at some stand and then continue in the direction of the discounts buying one ice cream sample box at each stand they visit in a consecutive sequence. Their goal is to collect at least one sample of each ice cream brand sold in the park. Simultaneously, to respect their stomach capacities, they want to minimize the total number of ice cream samples they buy.

Input Specification:

There are more test cases. Each case starts with a line containing two integers N, K separated by space (1 ≤ N, K ≤ 106 ). N is the number of ice cream stands, K is the total number of different ice cream brands sold at all stands. The brands are labeled by numbers 1, 2, . . . , K. Next, there are N lines describing stands in their visiting order. Each such line contains the list of brands of all ice cream samples sold in the sample box at that particular stand. Each list starts with one positive integer L, describing its length, followed by L integers. Each list item represents the brand of one ice cream sample in the sample box sold at this stand. You may assume that even if a visitor buys one sample box at each stand, he/she will collect at most 107 ice cream samples.

Output Specification:

For each test case, print a single line with one integer denoting the minimum number of ice cream samples Quido and Hugo have to buy in order to obtain a sample of each ice cream brand sold in the park. If it is impossible to obtain samples of all brands output −1.

题意:

这题的题意太难懂了,还是英语水平不够啊。抽象出来的题意是在给出的样例中找一个连续的区间,使得这个区间中的数包含1,2,3...,k这些数,而且数的个数要求最小。

思路:

是一个环,所以先将序列加倍,然后利用尺取法。

举个例子:N==3,K==3

1 1

1 2

3 1 2 3

尺取法做的时候第一次从左到右,1,2,3连在一起才是符合条件的,但是单独一个3也是符合条件的,而且数的个数更小。

所以这里就要注意:当得到一个符合条件的值的时候,我们让他的起点加一,直到不符合条件的情况出现,这个时候终点继续加一往后枚举。

之前做的尺取法都是遇到符合条件的情况后直接令起点等于终点继续枚举,思路还是没有拓展开。

代码:

#include 
#define inf 0x3f3f3f3f#define FRE() freopen("in.txt","r",stdin)using namespace std;typedef long long ll;const int maxn = 1e6+10;int vis[maxn];int N,K,ans;vector
v[maxn*2];int main(){ //FRE(); while(scanf("%d%d",&N,&K)!=EOF){ for(int i = 0; i
View Code

 

转载于:https://www.cnblogs.com/sykline/p/9878542.html

你可能感兴趣的文章
js2
查看>>
324. Wiggle Sort II
查看>>
129. Sum Root to Leaf Numbers
查看>>
Spark RDD详解
查看>>
[Codeforces Round #153 (Div. 2)]A. Little Xor
查看>>
AVFoundation 初识
查看>>
Web安全性测试
查看>>
Nginx+SignalR+Redis(一)windows
查看>>
整屏滚动
查看>>
Javascript的匿名函数与自执行
查看>>
.net中消息队列
查看>>
codeforces_1040_A Python练习
查看>>
用python处理文本数据 学到的一些东西
查看>>
UOJ #47.滑行的窗口
查看>>
P2504 聪明的猴子
查看>>
快速傅里叶变换(FFT)递归
查看>>
子窗口选择多值返回至父窗口的文本框中
查看>>
vi/vim编辑器必知必会(转)
查看>>
散列表(哈希表)工作原理 (转)
查看>>
敏捷开发产品管理系列之二:产品版本规划
查看>>