2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)
描述
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(简单思维)的更多相关文章
- 2017ICPC北京赛区网络赛 Minimum(数学+线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***
插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...
- hdu 4043 2011北京赛区网络赛D 概率+大数 **
推出公式为:P = A(2n,n)/(2^(2n)*n!) 但是不会大数,学完java再补
- hdu 4041 2011北京赛区网络赛B 搜索 ***
直接在字符串上搜索,注意逗号的处理 #include<cstdio> #include<iostream> #include<algorithm> #include ...
随机推荐
- 【Java】【2】String和List相互转换
正文: 1,String转List //常见的为逗号分隔 String str = "a,b,c"; List<String> list1 = Arrays.asLis ...
- leetcode-algorithms-18 4Sum
leetcode-algorithms-18 4Sum Given an array nums of n integers and an integer target, are there eleme ...
- IIS Web 服务器/ASP.NET 运行原理基本知识概念整理 转
转http://www.cnblogs.com/loongsoft/p/7272830.html IIS Web 服务器/ASP.NET 运行原理基本知识概念整理 前言: 记录 IIS 相 ...
- UI基础一:简单的BOL查询
利用标准的BOL编辑工具,添加BOL对象,重写查询方法,实现简答的BOL查询 1.SE11创建查询对象结构: 2.SE11创建查询结果对象: 3.SE24新建处理类: 重写查询结果方法: METHOD ...
- ECharts 报表事件联动系列二:柱状图,饼状图添加事件
代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...
- git相关知识(github,idea等的配置)
本地git提交文件到github上: 1.在github上创建项目 2.使用git clone https://github.com/xxxxxxx/xxxxx.git克隆到本地 3.编辑项目 4.g ...
- 部署java项目到服务器
1.首先判断服务器是什么系统 linux,windows 2.如果是linux使用SSH进行链接 3.如果是windows使用远程桌面进行链接 1.windows+R->mstsc进行远程桌面的 ...
- Const的使用
const意味为readonly,即只读,const可被施加于任何作用域内的对象,函数参数,函数返回类型,成员函数本体 使用: const修饰变量时本质是 const在谁后面谁就不可修改,const在 ...
- java中super和this的使用
要说super就先要说this."this",作为一个特殊的关键字,它的规则如下: 1.可以表示构造函数传递.this(a,b)表示调用另外一个构造函数.这里面的this就是一个特 ...
- 2015-09-28认识js1
Javascript 一.特点 1. 区分大小写 2. 弱类型变量,只能用关键字“var" 3.注释 /*….*/ 二. 变量 1.变量通过关键字var声明. 2.var ...