#1578 : 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

题目链接:

  http://hihocoder.com/problemset/problem/1578

题目大意:

  n天旅游时间,小明打算花其中连续的m天去北京玩,其中第一天a和另外一天b去参观清华,

  已知n天里参观清华排队的人数为p[i],目的是使得p[a]+p[b]最小。

  又因为北京有q天交通管制,所以实际上可以花连续k天,使得k天中恰有k-m天是交通管制,剩余m天游玩。

  

题目思路:

  【贪心】

  首先分析题目发现,其实要找连续k天满足其中有m天没交通管制,且第一天和其中一天p之和最小即可。

  k不固定,所以考虑将交通管制的天扣掉,这样找区间长度为m且满足p[a]+p[b]最小即可。

  直接暴力枚举,记录b的位置。

  然后将交通管制恢复,得到最终正确的答案。

 1 /****************************************************
 2
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.csdn.net/u010568270
 6
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=0.00001;
15 const int J=10;
16 const int MOD=1000000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=104;
20 using namespace std;
21 typedef long long LL;
22 double anss;
23 LL aans;
24 int cas,cass;
25 int n,m,lll,ans;
26 int a[N],b[N];
27 bool u[N];
28 int main()
29 {
30     #ifndef ONLINE_JUDGE
31 //    freopen("1.txt","r",stdin);
32 //    freopen("2.txt","w",stdout);
33     #endif
34     int i,j,k;
35     int x,y,z;
36 //    for(scanf("%d",&cass);cass;cass--)
37 //    init();
38 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
39     while(~scanf("%d",&n))
40     {
41         mem(u,0);
42         scanf("%d",&m);
43         for(i=0;i<n;i++)
44         {
45             scanf("%d",&a[i]);
46         }
47         scanf("%d",&cas);
48         for(i=1;i<=cas;i++)
49         {
50             scanf("%d",&x);
51             u[x]=1;
52         }
53         for(i=0,j=0;i<n;i++)
54         {
55             if(u[i])continue;
56             b[j++]=a[i];
57         }
58         ans=MAX;
59         for(i=0;i<=j-m;i++)
60         {
61             for(k=i+1;k<min(i+m,j);k++)
62             {
63                 if(b[i]+b[k]<ans)
64                 {
65                     ans=b[i]+b[k];
66                     y=i;z=k;
67                 }
68             }
69         }
70         for(i=0;i<n;i++)
71         {
72             if(u[i])continue;
73             if(!y)break;
74             y--;
75         }
76         y=i;
77         for(i=0;i<n;i++)
78         {
79             if(u[i])continue;
80             if(!z)break;
81             z--;
82         }
83         z=i;
84         printf("%d %d\n",y,z);
85     }
86     return 0;
87 }
88 /*
89 //
90
91 //
92 */

View Code

转载于:https://www.cnblogs.com/Coolxxx/p/7611760.html

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

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University

    ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University 题意,一个人去北京旅游,计划待m天,但是其中有一些天交通管制,不能出去,到 ...

  2. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题 Visiting Peking University

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

  3. 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem...

    题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...

  4. 【Java/补题/牛客/ACM赛制】2021年ICPC国际大学生程序设计竞赛暨陕西省第九届大学生程序设计竞赛(正式赛)

    文章目录 题目链接 知识一览 题目列表 快输 C - GCD(数论分块) 题目链接 2021年ICPC国际大学生程序设计竞赛暨陕西省第九届大学生程序设计竞赛(正式赛) 知识一览 01-数论分块 题目列 ...

  5. 计算机信息科学亚洲赛区冠军,祝贺竺院学子在ACM国际大学生程序设计竞赛亚洲赛区获得冠军...

    原标题:祝贺竺院学子在ACM国际大学生程序设计竞赛亚洲赛区获得冠军 Write the code. Change the World. 热烈祝贺竺可桢学院求是科学班(计算机)1601 陈靖邦.叶梓成, ...

  6. 2018ACM-ICPC国际大学生程序设计竞赛亚洲区域赛(青岛站)赛后总结

    这是今年最后一次打铁,我已经打了一年的铁了. 还是想写一个总结,不然,什么都会没留下. 实际上在去青岛之前,我已经一个月都没有严格地训练自己了,从9月份CCPC秦皇岛站打铁之后,我就基本上开始怀疑自己 ...

  7. 第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(沈阳)

    有时候,很简单的模板题,可能有人没有做出来,(特指 I ),到时候一定要把所有的题目全部看一遍 文章目录 B 题解 E F 题解 H I 题解&代码 J B 输入样例 3 2 1 2 1 2 ...

  8. 第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(上海)(热身赛(A/B) + 正式赛(D/E))

    热身赛 A. 虽然计算几何学了和没学差不多,但是板子题还是要会的(火速去补) 一定能形成折线,所以选最长的两个删掉就可以了 struct node {double dist;int x; };int ...

  9. 第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(上海)DEGHI

    D Strange_Fractions 令t=b/a,可以得到关于t的一元二次方程,用根的存在定理以及根是否为整数判断是否存在解,若有解,用求根方式求出t来,取t=(p+sqrt(p^2 -4q^2) ...

最新文章

  1. Software-Defined Networking之搬砖的故事
  2. Sudo 授权需谨慎,否则脸上泪两行
  3. Es-nested嵌入式属性
  4. java: 十六进制转八进制
  5. 半夜三点,去医院看病。。。
  6. 程序媛计划——python初级class5~13
  7. Samba Linux 和windows 共享
  8. 小学计算机课程评价,小学信息技术课堂评价浅谈
  9. java 操作日志记录_高效日志系统搭建秘技!架构师必读
  10. 计算机与打印机脱机后怎么共享,打印机脱机工作怎么恢复(连接的共享打印机脱机)...
  11. STM32, ADS1115
  12. 传染病研究-靶向下一代宏基因组测序(mNGS)分析
  13. java 视频边下边播,android 边下边播放mp3完美实现(有缓冲和播放进度效果)
  14. 如何实现文字逐个出现的打字机效果
  15. LeetCode题解(1425):带限制的子序列和(Python)
  16. java设置页码_Java 添加页码到Word文档
  17. 大姨妈的由来【摘字古书】
  18. 【无人机】无人机的气象数据采集系统设计(Matlab代码实现)
  19. HeidiSQL日常使用
  20. SVM转化为对偶问题求解的原因

热门文章

  1. 网上税务html模板,HTML黑色欧美形式税务动态邮件网页模板代码
  2. 编辑器插件不生效在html中,关于6.04版本HTML编辑器插件使用问题!
  3. ubuntu linux的特点,16个新特性,让你爱上Ubuntu 20.04,
  4. java生成流水号001_可变数据如何批量生成?
  5. php ado,常用的php ADODB使用方法集锦
  6. 写得太好了!树莓派安装docker
  7. 【Deep Learning笔记】前馈神经网络和BP算法
  8. 解决Python memory error的问题--扩充虚拟内存
  9. Imagenet VGG-19网络加载和特征可视化
  10. Windows环境下配置环境变量