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天其他任意一天去北大,是的去的时候人最少。每天去北大的人数也给出,保证有答案。暴力做就可以
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 int n,m,q;
 6 int p[105];
 7 bool vis[103];
 8 int ans,ansa,ansb, ans1,ansa1,ansb1;
 9 int main()
10 {
11    while(~scanf("%d%d",&n,&m))
12    {
13     for(int i=0;i<n;i++) {scanf("%d",&p[i]); vis[i]=1;}
14     scanf("%d",&q);
15      for(int i=1;i<=q;i++)
16      {
17          int x;
18          scanf("%d",&x);
19          vis[x]=0;
20      }
21      ans=0x7fffffff;
22      ansa=-1;
23      ansb=-1;
24      for(int i=0;i<=n-m;i++)
25      {
26          if (vis[i]==0) continue;
27          int day=1;
28          ans1=ans;
29          ansa1=ansa;
30          ansb1=ansb;
31          for(int j=i+1;j<n;j++)
32          {
33             if (vis[j]==0) continue;
34             day++;
35             if(p[j]+p[i]<ans1)
36                 { ans1=p[i]+p[j]; ansa1=i; ansb1=j;}
37             if (day==m)
38             {
39                 if (ans1<ans){ans=ans1;ansa=ansa1;ansb=ansb1;}
40                 break;
41             }
42          }
43
44      }
45      printf("%d %d\n",ansa,ansb);
46    }
47     return 0;
48 }
时间: 2024-10-25 19:46:46

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. Output Minx,y∈[l,r] {ax?ay}. 2. Let ax=y. 输入 The first line is an integer T, indicating the number of test cases. (1≤T≤10). For each test case: The fi

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

插板法基础知识 斯特林数见百科 1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstring> 5 #define LL long long 6 #define eps 1e-7 7 #define MOD 1000000007 8 using namespace std; 9 int c[2001][2001]={1},stir2[1005][1005]={1};

2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6

题目链接: #1228 : Mission Impossible 6 解题思路: 认真读题,细心模拟,注意细节,就没有什么咯!写这个题解就是想记录一下rope的用法,以后忘记方便复习. rope(块状链表)属于SGI STL的一部分,不属于ISO C++标准库,但libstdc++-v3也包含了扩展,在头文件#include<ext/rope>,using namespace __gnu_cxx命名空间中.可以在很短的时间内实现快速的插入.删除和查找字符串. rope.size()    返回

2015 ACM-ICPC 北京赛区 网络赛 部分 题解

由于博主水平及智商不足,所以暂时只能放出下列的题目的题解. A B D F G H 需要其他题解请自行前往 http://talk.icpc-camp.org/ 题目地址:hihocoder 1227-1236 A.  The Cats' Feeding Spots 题意:给出M个点,求以其中一个点为圆心,最小半径的圆,使得这个圆里恰好有N个点. (半径一定要是整数,且点不能恰好在圆上). 方法:暴力,稍微注意一下精度什么的就好了,1A. 1 #include <bits/stdc++.h>

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

题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到达这个格子 1:表示左脚跳进这个格子 2:表示右脚跳进这个格子 3:随意哪个脚跳进这个格子,而且下一步随意用哪个脚 dp[i][j] :表示走到第 i 个格子在 j 状态的期望. 当j=1时,你可以走到dp[i+k][2],dp[i+k][3], 当j=2时,你可以走到dp[i+k][1],dp[i

2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)

Let SSS be a sequence of integers s1s_{1}s?1??, s2s_{2}s?2??, ........., sns_{n}s?n?? Each integer is is associated with a weight by the following rules: (1) If is is negative, then its weight is 000. (2) If is is greater than or equal to 10000100001

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

cl少用在for循环里 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x

hdu 4046 2011北京赛区网络赛G 线段树 ***

还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w 1 #include<cstdio> 2 #include<cstring> 3 #define lson l,m,rt<<1 4 #define rson m+1,r,rt<<1|1 5 using namespace std; 6 const int maxn=50010; 7 int n,m,sum[maxn<<2]; 8 char str[ma

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

直接在字符串上搜索,注意逗号的处理 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 #define pb