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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

记录奥林比克/课程录制 洛谷P2255 [USACO14JAN]

發布時間:2025/6/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记录奥林比克/课程录制 洛谷P2255 [USACO14JAN] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題面在最下方。

本題貪心可解,我也不是很懂動規解法(雙線程DP?)

先把各個課程(比賽)按結束時間從小到大排序,記錄兩個攝像機的結束時間。

然后枚舉課程,如果某個課程的開始時間早于任何一臺攝像機的結束時間,則該課程不能被錄制,如果某個課程只能用某臺攝像機錄制,則安排該臺攝像機錄制,如果某個課程能被兩臺攝像機錄制,那么根據貪心應該選擇結束時間大的那一個攝像機。
時間復雜度:? 排序sort O(N log N)? 枚舉 O(n)。

附上AC代碼

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 template<class T> inline void read(T &_a){ 6 int _ch=getchar();_a=0; 7 while(_ch<'0' || _ch>'9')_ch=getchar(); 8 while(_ch>='0' && _ch<='9'){_a=(_a<<1)+(_a<<3)+_ch-'0';_ch=getchar();} 9 } 10 11 const int maxn=151; 12 struct lesson 13 { 14 int s,t; 15 inline bool operator < (const lesson x) const {return t<x.t;} 16 }node[maxn]; 17 int n,ans,s1,s2; 18 19 int main() 20 { 21 freopen("record.in","r",stdin); 22 freopen("record.out","w",stdout); 23 read(n); 24 if(n<=2) {printf("%d",n); return 0;} 25 for (register int i=1;i<=n;++i) read(node[i].s),read(node[i].t); 26 sort(node+1,node+n+1); 27 for (register int i=1;i<=n;++i) 28 { 29 if(node[i].s<s1&&node[i].s<s2) continue; 30 ++ans; 31 if(node[i].s>=s1&&node[i].s<s2) s1=node[i].t; 32 else if (node[i].s<s1&&node[i].s>=s2) s2=node[i].t; 33 else if (s1<s2) s2=node[i].t; 34 else s1=node[i].t; 35 } 36 printf("%d",ans); 37 return 0; 38 } View Code

?

動規說明:

法二:DP

雙線程DP

先sort

然后對于f[i,j],表示現在同時錄制i和j,接下來(包括i和j)最多能錄制多少(i<=j)

f[k,j]+1 { i<k<j,且a[k]>=b[i] }

那么f[i,j]=max{f[j,k]+1 { j<k 且 a[k]>=b[i]}

?

中文版

題目描述:

要開運動會了,神犇學校的n個班級要選班服,班服共有100種樣式,編號1~100。現在每個班都挑出了一些樣式待選,每個班最多有100個待選的樣式。要求每個班最終選定一種樣式作為班服,且該班的樣式不能與其他班級的相同,求所有可能方案的總數,由于方案總數可能很大,所以要求輸出mod 1000000007后的答案。

輸入描述:

共有T組數據。

對于每組數據,第一行為一個整數n,表示有n個班級。

2~n+1行,每行有最多100個數字,表示第i-1班待選班服的編號。

輸出描述:

對于每組數據,輸出方案總數 mod 1000000007后的答案。

樣例輸入:

2

3

5 100 1

2

5 100

2

3 5

8 100

樣例輸出:

4

4

數據范圍:

對于30%的數據,1<=T<=3, 1<=n<=3,每班待選樣式不超過10種。

對于50%的數據,1<=T<=5, 1<=n<=5,每班待選樣式不超過50種。

對于100%的數據,1<=T<=10, 1<=n<=10,每班待選樣式不超過100種。

?

英文版(洛谷)

題目描述

Being a fan of all cold-weather sports (especially those involving cows),

Farmer John wants to record as much of the upcoming winter Moolympics as

possible.

The television schedule for the Moolympics consists of N different programs

(1 <= N <= 150), each with a designated starting time and ending time. FJ

has a dual-tuner recorder that can record two programs simultaneously.

Please help him determine the maximum number of programs he can record in

total. 冬奧會的電視時刻表包含N (1 <= N <= 150)個節目,每個節目都有開始和結束時間。農民約翰有兩臺錄像機,請計算他最多可以錄制多少個節目。

輸入輸出格式

輸入格式:

  • Line 1: The integer N.

  • Lines 2..1+N: Each line contains the start and end time of a single

program (integers in the range 0..1,000,000,000).

?

輸出格式:

  • Line 1: The maximum number of programs FJ can record.

輸入輸出樣例

輸入樣例#1:
6 0 3 6 7 3 10 1 5 2 8 1 9 輸出樣例#1:
4

說明

INPUT DETAILS:

The Moolympics broadcast consists of 6 programs. The first runs from time

0 to time 3, and so on.

OUTPUT DETAILS:

FJ can record at most 4 programs. For example, he can record programs 1

and 3 back-to-back on the first tuner, and programs 2 and 4 on the second

tuner.

Source: USACO 2014 January Contest, Silver

轉載于:https://www.cnblogs.com/jaywang/p/7701818.html

總結

以上是生活随笔為你收集整理的记录奥林比克/课程录制 洛谷P2255 [USACO14JAN]的全部內容,希望文章能夠幫你解決所遇到的問題。

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