题目1 : Visiting Peking University

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, …, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. During these m days, he intends to use the first day and another day to visit Peking university. Before he made his plan, Ming investigated on the number of tourists who would be waiting in line to enter Peking university during his n-day trip, and the results could be represented by an integer sequence p[i] (0 ≤ i ≤ n-1, p[i] represents the number of waiting tourists on day i). To save time, he hopes to choose two certain dates a and b to visit PKU(0 ≤ a < b ≤ n-1), which makes p[a] + p[b] as small as possible.

Unfortunately, Ming comes to know that traffic control will be taking place in Beijing on some days during his n-day trip, and he won’t be able to visit any place in Beijing, including PKU, on a traffic control day. Ming loves Beijing and he wants to make sure that m days can be used to visit interesting places in Beijing. So Ming made a decision:  spending k (m ≤ k ≤ n) consecutive days in Beijing is also acceptable if there are k - m traffic control days among those k days. Under this complicated situation, he doesn’t know how to make the best schedule. Please write a program to help Ming determine the best dates of the two days to visit Peking University.  Data guarantees a unique solution.

输入

There are no more than 20 test cases.

For each test case:

The first line contains two integers, above mentioned n and m (2 ≤ n ≤ 100, 2 ≤ m ≤ n).

The second line contains n integers, above mentioned p[0] , p[1] , … p[n-1]. (0 ≤ p[i] ≤ 1000, i = 0 ... n-1)

The third line is an integer q (0 ≤ q ≤ n), representing the total number of traffic control days during the n-day trip, followed by q integers representing the dates of these days.

输出

One line, including two integers a and b, representing the best dates for visiting PKU.

样例输入
7 3
6 9 10 1 0 8 35
3 5 6 2
4 2
10 11 1 2
1 2
样例输出
0 3
1 3 【题意】:题意是一人去旅游n天,在北京待连续的m天,他想去参观PKU,他知道这n天参观排队的人数,但是有q天交通管制,哪都去不了。所以他决定待K天,但是有要求,在前K天中,只要有K~M天是交通管制时间,他可以在连续的m天区间内选择任意两天参观,问最少排队人数是多少,注意排队人数的下标是0~n-1,但管制天数是1—n,最后输出这两天(下标)。 【分析】:重点是枚举起点天。第一组数据中2、6、5天交通管制,将它们从数组删去。剩下6(0) 9(1) 1(3) 0(4).三天的组合—>6 9 1中选2天 or 9 1 0 中选2天。求和后比较取最小值。(注意每个情况的第一天是必须选的)。则必须选择第0或1天作为游览的第一天,否则无法保证总共游览m=3天。若选第0天开始,则最佳方案是第0和第3天,排队总人数是6+1=7。若选第1天作为开始,则最佳方案是第1和第4天,9+0=9。所以最终的方案是第0和第3天。 【代码】:
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
#define inf 0x3f3f3f3f
struct node
{
int re,id;
}b[maxn];
int main()
{
int n,m,k;
int a[maxn];
int q,x;
int vis[maxn];
while(~scanf("%d%d",&n,&m))
{
k=;
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
} scanf("%d",&q);
for(int i=; i<q; i++)
{
scanf("%d",&x);
vis[x]=;
} for(int i=;i<n;i++)
{
if(!vis[i])
{
b[k].re=a[i];
b[k++].id=i;
//k++;
}
} int minn=inf,l=,r=;//
for(int i=;i+m<=k;i++)
{
int x=b[i].re;
for(int j=;j<m;j++)
{
if(b[i+j].re+x < minn)
{
minn=b[i+j].re+x;
l=b[i].id;
r=b[i+j].id;
}
}
}
printf("%d %d\n",l,r);
}
}

0ms


ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】的更多相关文章

  1. ACM-ICPC北京赛区(2017)网络赛2【后缀数组+Java//不会】

    #1579 : Reverse Suffix Array 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strong data structure ...

  2. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  3. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  4. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  5. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  6. ACM-ICPC北京赛区(2017)网络赛_Minimum

    题目9 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, -, a2^k ...

  7. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

  8. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  9. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

随机推荐

  1. 2017博普杯 东北大学邀请赛(B. Drink too much water)(贪心+树链剖分)

    题目地址:https://oj.neu.edu.cn/problem/1204 题目大意: 其实就是树上的线段覆盖, 给出一棵n个结点的树,然后给出树上的一些路径进行覆盖,然后要求选取最少的点,能够把 ...

  2. SRM710 div1 ReverseMancala(trick)

    题目大意, 给定一个有n个点的环,n不超过10,每个点上有一个权重 起始时权重将会给出,然后有2种操作 第一种操作是,选择一个位置i,获得权重w = a[i],把a[i]变成0,然后接下来在环上顺着走 ...

  3. Codeforces Round #392 (div.2) E:Broken Tree

    orz一开始想不画图做这个题(然后脑袋就炸了,思维能力有待提高) 我的做法是动态规划+贪心+构造 首先把题目给的树变成一个可行的情况,同时weight最小 这个可以通过动态规划解决 dp[x]表示以x ...

  4. 安全警告——“Windows已经阻止此软件因为无法验证发行者”解决办法

    步骤:打开IE工具-->Internet选项-->安全-->自定义级别 -->找到ActiveX 控件和插件,按照图里进行配置.

  5. [luogu P1442] 铁球落地

    题目链接 线段树\(+dp\). 先用线段树预处理出每个线段从左边和右边掉落到哪里,记为\(f[i][0/1]\). 然后记\(g[i][0/1]\)为到达第\(i\)个线段的左边或右边所要的最小时间 ...

  6. [BZOJ3196][Tyvj1730]二逼平衡树

    [BZOJ3196][Tyvj1730]二逼平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询 \(k\) 在区间内的排名 查询区间内排名为 \ ...

  7. java一个接口可以继承另外一个接口吗

    一个接口可以继承多个接口. interface C extends A, B {}是可以的. 一个类可以实现多个接口: class D implements A,B,C{} 但是一个类只能继承一个类, ...

  8. Codeforces Round #523 (Div. 2) A. Coins

    A. Coins 题目链接:https://codeforc.es/contest/1061/problem/A 题意: 给出n和s,要在1-n中选数(可重复),问最少选多少数可以使其和为s. 题解: ...

  9. Oulipo HDU - 1686

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  10. idea初学建立maven项目报错

    原理,是因为你没把新创建好的maven项目给设置成一个可被tomcat部署的web项目 参考此博文,讲的非常详细: 归根到底是因为web项目的部署问题: 解决方案:在创建的到时候,idea下部会提示是 ...