描述

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. mysql 8.0.12 修改root密码

    use mysql: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; FLUSH PRIVI ...

  2. C++ string的用法和例子

    使用场合: string是C++标准库的一个重要的部分,主要用于字符串处理.可以使用输入输出流方式直接进行操作,也可以通过文件等手段进行操作.同时C++的算法库对string也有着很好的支持,而且st ...

  3. InnoDB存储引擎介绍-(7) Innodb数据页结构

    数据页结构 File Header 总共38 Bytes,记录页的头信息 名称 大小(Bytes) 描述 FIL_PAGE_SPACE 4 该页的checksum值 FIL_PAGE_OFFSET 4 ...

  4. Spring注解之@Transactional对于事务异常的处理

    spring对于事务异常的处理 unchecked   运行期Exception   spring默认会进行事务回滚       比如:RuntimeException checked       用 ...

  5. asm ftp utilty and usage

    Oracle 11g ASM supports ASM FTP, by which operations on ASM files and directories can be performed s ...

  6. vue2.0 transition 手风琴

    <div class="food"> <button @click="show=!show">show</button> & ...

  7. rdesktop安装教程

    1.介绍 rdesktop是Linux下连接windows远程桌面的工具 2.下载 https://github.com/rdesktop/rdesktop/releases 3.安装 mkdir / ...

  8. oo作业总结报告2

    第五次作业 多线程电梯 多线程同步和控制的设计策略 明确类和对象,以及是否区分对象实例.具体类可以从类图中看出: 明确线程的类型和数量.输入作为一个线程,调度作为一个线程,三个电梯独立工作,互不影响, ...

  9. c# 关于async/await异步编程的浅析和使用

    线程的同步运行,时效性慢,异步运行,时效性快! 在c#5.0引出了async/await关键字,可以用其来进行异步编程. async/await定义异步方法的语法如下: 1.在方法的返回类型前面加上a ...

  10. PC/FORTH 数字类型

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...