ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
来源:互联网 发布:蓝牙打印机测试软件 编辑:程序博客网 时间:2024/05/23 01:23
- 样例输入
7 36 9 10 1 0 8 353 5 6 24 210 11 1 21 2
- 样例输出
0 31 3
描述
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.
代码:
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;int main(){ int N, M; int p[110]; int vis[110]; int t, d, k; int ans, sum, si, ei; while(~scanf("%d%d", &N, &M)) { memset(vis, 0, sizeof(vis)); for(int i=0; i<N; i++) { scanf("%d", &p[i]); } scanf("%d", &t); for(int i=0; i<t; i++) { scanf("%d", &d); vis[d]=1; } ans=1e9;//极大值 for(int i=0; i<N; i++)//0天开始 { if(vis[i]==1)//t-- 还剩 t 天管制 { t--; continue; } if(i+M+t>N)//剩余天数不足 { continue; } k=i+M;// sum=p[i];//第一天去 int minn=1e9; int mins, mine;//去PKU的两天 mins=i;//第一天 for(int j=i+1; j<k; j++) { if(vis[j]==1)//管制 { k++; continue; } if(minn>p[j]) { minn=p[j]; mine=j; } } sum+=minn; if(ans>sum) { ans=sum; si=mins; ei=mine; } } printf("%d %d\n", si, ei); } return 0;}
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目1 : Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题 Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A.Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-A-Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University(模拟水题)
- HihoCoder-1578 Visiting Peking University(模拟,ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- Visiting Peking University 2017ACM-ICPC亚洲区(北京赛区)网络赛题目1
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum-(线段树)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum(线段树)
- Minimum (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题9)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 Minimum
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E.Territorial Dispute
- 线段树 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 HihoCoder 1586
- mongo 脚本整理
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum(线段树)
- Spring MVC 浅析
- leetcode--PascalTriangle
- 统计学简介之十一——假设检验定义
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
- HTTP状态码
- Java中的多线程你只要看这一篇就够了
- cookie的使用
- Problem 63 Powerful digit counts
- 天天写业务代码的程序员,怎么成为技术大牛,开始写技术代码?
- Mybatis基础
- JavaScript特殊字符
- 【秋招面经】2017秋招面经整理