Tickets HDU - 1260
题意:
有n个人要买票,卖票时,可以给一个人卖,也可以同时给相邻的两个人卖。
每个人的时间为
s
[
i
]
s[i]
s[i]
每个相邻组合的时间
d
[
i
]
d[i]
d[i]
求:
最少的时间。
学习:
- c++结构体赋值,相比于其他面向对象语言的区别。
在一个结构体内调用其他构造函数 - c++初始化,还有一个初始化列表
思路:
本题先不看输出:
- 当前状态 d p [ i ] = m i n ( d p [ i − 1 ] + s [ i ] , d p [ i − 2 ] + d [ i ] ) dp[i] = min(dp[i-1]+s[i], dp[i-2]+d[i]) dp[i]=min(dp[i−1]+s[i],dp[i−2]+d[i])
之后就是输出:
- 其实就是模拟而已
AC
/*
皮卡丘冲鸭!
へ /|
/\7 ∠_/
/ │ / /
│ Z _,< / /`ヽ
│ ヽ / 〉
Y ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―r ̄ ̄`ー―_
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <cmath>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define ALL(x) x.begin(),x.end()
#define mp make_pair
#define fi first
#define se second
#define db double
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
typedef pair<db,db> pdd;
const int N = 2e5+10;
const int M = 1e5;
const int maxn=1e6+10;
const db eps = 1e-8;
const db pi = acos(-1.0);
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const char ty[2][4]={"am", "pm"};
struct Time{
int h, m ,s;
char cur[5];
Time(){}
/*
Time(int h, int m, int s){
this->h = h;
this->m = m;
this->s = s;
}
*/
Time(int _h, int _m, int _s):h(_h), m(_m), s(_s){}
Time(int h, int m, int s, char type[]){
new(this)Time(h,m,s);
direct();
if(this->h >= 12) memcpy(this->cur,ty[1],sizeof(cur));
else memcpy(this->cur, ty[0],sizeof(cur));//cur = "AM";
}
void print(){
printf("%02d:%02d:%02d %s", h, m, s, cur);
}
Time operator +(const Time &b){
/*
Time c;
int h = this->h + b.h;
int m = this->m + b.m;
int s = this->s + b.s;
//direct();
c = Time(h,m,s,"");
*/
Time c = Time(h + b.h, m + b.m, s + b.s, "");
return c;
}
void direct(){
if(s>60)m+=s/60, s = s%60;
if(m>60)h+=m/60, m = m%60;
if(h>=24)h%=24;
}
} t8;
int dp[3000];
int s[3000], d[3000];
void sol(){
int n;
scanf("%d", &n);
For(i,1,n)scanf("%d", s+i);
For(i,2,n) scanf("%d", d+i);
dp[1] = s[1];
For(i,2,n){
dp[i] = min(dp[i-1]+s[i],dp[i-2]+d[i]);
}
int h = 0, m =0 ,s = 0;
s = dp[n]%60; m += dp[n]/60;
h += m/60, m = m%60;
Time add = Time(h,m,s,"");
Time now = add+t8;
now.print();
puts("");
}
int main()
{
t8 = Time(8,0,0,"");
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*
Time t1 = Time(8,0,0,"");
Time t2 = Time(12,0,0,"");
t2.print();
puts("");
Time t3 = t2 + t1;
// debug(t1.h);
t1.print();
puts("");
t2.print();
t3.print();
*/
int tt;
scanf("%d", &tt);
while(tt--){
sol();
}
return 0;
}