日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/4/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题 Visiting Peking University 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目1 : Visiting Peking University

時間限制:1000ms

單點時限:1000ms

內存限制:256MB

描述

Ming is going to travel for n days and the date of these dayscan be represented by n integers: 0, 1, 2, …, n-1. He plans to spend mconsecutive days2 ≤ m ≤ ninBeijing. During these m days, he intends to use the first day and another dayto visit Peking university. Before he made his plan, Ming investigated on thenumber of tourists who would be waiting in line to enter Peking universityduring his n-day trip, and the results could be represented by an integersequence p[i] (0 ≤ i ≤ n-1, p[i] represents the number of waiting tourists onday i). To save time, he hopes to choose two certain dates a and b to visitPKU(0 ≤ a < b ≤ n-1), which makes p[a] + p[b] as small as possible.

Unfortunately, Ming comes to know that traffic control will betaking place in Beijing on some days during his n-day trip, and he won’t beable 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 visitinteresting 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 trafficcontrol days among those k days. Under this complicated situation, he doesn’tknow how to make the best schedule. Please write a program to help Mingdetermine the best dates of the two days to visit Peking University. ?Dataguarantees 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 thetotal number of traffic control days during the n-day trip, followed by q integersrepresenting the dates of these days.

輸出

One line, including two integers a and b, representing the bestdates 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 ,m 第二行有n個數,分別代表第0,1,2....n-1天在北京大學等待的人數 第三行輸入一個k個數,接下來又有k個數表示交通限制的日期是多少 現在要從沒被限制交通的日期里面選擇連續的m天去到北大旅行,在m天里面選擇兩天(這兩天的第一天必須是連續m天中的第一天,兩天中的等待人數之和又必須是最小) 最后輸出連續的m天中選擇的兩天的日期是多少*/ #include <iostream>using namespace std;struct aa{int which_day;int wait_people;}a[101];int main(){int all_wait_people[101];int n,m,limit_days;while(cin>>n>>m){for(int i=0;i<n;++i)cin>>all_wait_people[i];cin>>limit_days;int day;for(int i=0;i<limit_days;++i){cin>>day;all_wait_people[day]=-1;}int j=0;for(int i=0;i<n;++i){if(all_wait_people[i]!=-1){a[j].which_day=i;a[j++].wait_people=all_wait_people[i];}}int a0,a1,min=1000;for(int i=0;i<=j-m;i++)//不確定i的上界可以把樣例中的第一組數據帶入驗證{for(int k=i+1;k<m+i;k++)if(a[i].wait_people+a[k].wait_people<min){min=a[i].wait_people+a[k].wait_people;a0=a[i].which_day;a1=a[k].which_day;}}cout<<a0<<' '<<a1<<endl;}return 0;} 附上隊友的: #include <iostream> #include <cstdio> using namespace std; #define MAX 1005 struct Node {int data;int num; }; int main() {int n,m;Node p[MAX],P[MAX];while(scanf("%d%d",&n,&m)!=EOF){int i;for(i=0;i<n;i++){scanf("%d",&p[i].data);p[i].num = i;}int q,k;scanf("%d",&q);for(i=0;i<q;i++){scanf("%d",&k);p[k].data = -1;}int j = 0,min = MAX;for(i=0;i<n;i++)if(p[i].data!=-1){P[j].data = p[i].data;P[j].num = p[i].num;j++;}int start,end;for(i=0;i<=j-m;i++){for(k = i+1;k<i+m;k++){if(P[i].data+P[k].data<min){min = P[i].data+P[k].data;start = P[i].num;end = P[k].num;}}}printf("%d %d\n",start,end);}return 0; }


《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题 Visiting Peking University的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。