描述

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天,在北京待k天(连续),其中恰好k-m天不能出行;
要求这k天里第一天和K天其他任意一天去北大,是的去的时候人最少。
每天去北大的人数也给出,保证有答案。
暴力做就可以
 #include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q;
int p[];
bool vis[];
int ans,ansa,ansb, ans1,ansa1,ansb1;
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<n;i++) {scanf("%d",&p[i]); vis[i]=;}
scanf("%d",&q);
for(int i=;i<=q;i++)
{
int x;
scanf("%d",&x);
vis[x]=;
}
ans=0x7fffffff;
ansa=-;
ansb=-;
for(int i=;i<=n-m;i++)
{
if (vis[i]==) continue;
int day=;
ans1=ans;
ansa1=ansa;
ansb1=ansb;
for(int j=i+;j<n;j++)
{
if (vis[j]==) continue;
day++;
if(p[j]+p[i]<ans1)
{ ans1=p[i]+p[j]; ansa1=i; ansb1=j;}
if (day==m)
{
if (ans1<ans){ans=ans1;ansa=ansa1;ansb=ansb1;}
break;
}
} }
printf("%d %d\n",ansa,ansb);
}
return ;
}

2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)的更多相关文章

  1. 2017ICPC北京赛区网络赛 Minimum(数学+线段树)

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

  2. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  3. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  4. hdu 4044 2011北京赛区网络赛E 树形dp ****

    专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...

  5. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  6. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  7. hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***

    插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...

  8. hdu 4043 2011北京赛区网络赛D 概率+大数 **

    推出公式为:P = A(2n,n)/(2^(2n)*n!) 但是不会大数,学完java再补

  9. hdu 4041 2011北京赛区网络赛B 搜索 ***

    直接在字符串上搜索,注意逗号的处理 #include<cstdio> #include<iostream> #include<algorithm> #include ...

随机推荐

  1. 在c++运行后出现PDB或者什么巴拉巴拉已经加载符号了的话

    “stl常用排序算法.exe”(Win32): 已加载“E:\vs2015\project\stl常用排序算法\Debug\stl常用排序算法.exe”.已加载符号. “stl常用排序算法.exe”( ...

  2. Vue引入jQuery

    1.在项目中安装jquery npm install jquery --save-dev 或者 打开package.json文件,在里面加入这行代码,jquery后面的是版本,根据你自己需求更改. d ...

  3. UI界面按钮增强

    (我是菜鸟,知道的少) 1.有HTML页面代码的,可以编辑 <%@page language="abap" %> <%@extension name=" ...

  4. PHP手册-函数参考-加密扩展

    一.Crack.CSPRNG.Hash.Mcrypt.Mhash.OpenSSL.密码散列算法的对比   Crack CSPRNG Hash Mcrypt Mhash OpenSSL 密码散列算法 简 ...

  5. 【转】借助System.Linq.Dynamic, IQueryable根据排序字符串排序

    在使用Entity Framework时,若有多个排序,需要OrderBy (OrderByDescending)再ThenBy (ThenByDescending) 假设需要根据Name升序排序,再 ...

  6. 两个有序数组的中位数(第k大的数)

    问题:两个已经排好序的数组,找出两个数组合并后的中位数(如果两个数组的元素数目是偶数,返回上中位数). 感觉这种题目挺难的,尤其是将算法完全写对.因为当初自己微软面试的时候遇到了,但是没有想出来思路. ...

  7. killl prefix out macro mis mal micro -m

    1● macro 宏大,规模大   2● mis 错误,坏   3● mal 坏,错误   4● micro 小,微小  

  8. memory prefix inter,intra,intro,iso out 5

    1● inter 在~之间:相互   2● intra 3● iso 等 同   4● intro 向内,在内,内部  

  9. sigmoid belief network boltszmann machine

    because of explaining away, the hidden weights in sigmoid belief network is no longer independent

  10. day29-python阶段性复习三

    七.python打开文件方式 open r: 读的方式 w:已写的方式打开 a:以追加的方式 r+ 读写模式 w+ 读写 a+ 读写 rb:二进制读模式打开 wb:以二进制写模式打开 ab 二进制追加 ...