生活随笔
收集整理的這篇文章主要介紹了
【智力大冲浪】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【智力大沖浪】
riddle
內存限制: 128M
【題目描述】
例 1 智力大沖浪(riddle.pas)。
【題目描述】
小偉報名參加中央電視臺的智力大沖浪節目。本次挑戰賽吸引了眾多
參賽者,主持人為了表彰大家的勇氣,先獎勵每個參賽者 m 元。先
不要太高興!因為這些錢還不一定都是你的。接下來主持人宣布了比
賽規則:
首先,比賽時間分為 n 個時段(n≤500),它又給出了很多小游戲,每
個小游戲都必須在規定期限 ti 前完成(1≤ti≤n)。如果一個游戲沒能
在規定期限前完成,則要從獎勵費 m 元中扣去一部分錢 wi, wi 為自
然數,不同的游戲扣去的錢是不一樣的。當然,每個游戲本身都很簡
單,保證每個參賽者都能在一個時段內完成,而且都必須從整時段開
始。主持人只是想考考每個參賽者如何安排組織自己做游戲的順序。
作為參賽者,小偉很想贏得冠軍,當然更想贏取最多的錢!
注意:比賽絕對不會讓參賽者賠錢!
【輸入】
輸入文件 riddle.in,共 4 行。
第一行為 m,表示一開始獎勵給每位參賽者的錢;
第二行為 n,表示有 n 個小游戲;
第三行有 n 個數,分別表示游戲 1~n 的規定完成期限;
第四行有 n 個數,分別表示游戲 1~n 不能在規定期限前完成的扣
數。
【輸出】
輸出文件 riddle.out,僅 1 行。表示小偉能贏取最多的錢。
【樣例輸入】
10000
7
4 2 4 3 1 4 6
70 60 50 40 30 20 10
【樣例輸出】
9950
題解:
損失的最少,等價于先都減去再加回來,再跑一遍01背包。
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<vector>
6 #include<map>
7 #include<
set>
8 #include<cmath>
9 #include<ctime>
10 #define inf 2147483647
11 #define p(a) putchar(a)
12 #define g() getchar()
13 #define For(i,a,b) for(register int i=a;i<=b;i++)
14 //by war
15 //2017.10.24
16 using namespace std;
17 int m;
18 int n;
19 //int t[510];
20 //int v[510];
21 int f[
510];
22 int Max;
23 struct jl
24 {
25 int t;
26 int v;
27 bool operator<(
const jl&aa)
const
28 {
29 return t<
aa.t;
30 }
31 }a[
510];
32
33 void in(
int &
x)
34 {
35 int y=
1;
36 char c=g();x=
0;
37 while(c<
'0'||c>
'9')
38 {
39 if(c==
'-')
40 y=-
1;
41 c=
g();
42 }
43 while(c>=
'0'&&c<=
'9')x=x*
10+c-
'0',c=
g();
44 x*=
y;
45 }
46 void o(
int x)
47 {
48 if(x<
0)
49 {
50 p(
'-');
51 x=-
x;
52 }
53 if(x>
9)o(x/
10);
54 p(x%
10+
'0');
55 }
56 int main()
57 {
58 freopen(
"riddle.in",
"r",stdin);
59 freopen(
"riddle.out",
"w",stdout);
60 in(m),
in(n);
61 For(i,
1,n)
62 in(a[i].t);
63 For(i,
1,n)
64 in(a[i].v),m-=
a[i].v;
65 sort(a+
1,a+n+
1);
66 For(i,
1,n)
67 for(register
int j=a[i].t;j>=
1;j--
)
68 f[j]=max(f[j],f[j-
1]+
a[i].v);
69 Max=-
inf;
70 For(i,
1,n)
71 Max=
max(Max,f[i]);
72 o(Max+
m);
73 return 0;
74 }
?
轉載于:https://www.cnblogs.com/war1111/p/7722789.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的【智力大冲浪】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。