H: Jazz Enthusiast
题意: 将给出的时间相加运算即可
#include<bits/stdc++.h>
using namespace std;
int h[10001];
int m[10001];
int s[10001];
int hh, mm, ss;
int T;
int main(){
int n, c;
cin >>n >>c;
mm = 0;
ss = 0;
hh = 0;
char cc;
for(int i = 0; i < n; i++){
cin >> m[i] >> cc >> s[i];
mm += m[i];
ss += s[i];
}
ss -= c *(n-1);
int s_ = ss % 60;
mm += ss / 60;
int m_ = mm % 60;
hh = mm / 60;
printf("%02d:%02d:%02d\n", hh, m_, s_);
}
这个wa了 一直不知道为什么
ac码
#include<bits/stdc++.h>
using namespace std;
int h[10001];
int m[10001];
int s[10001];
int hh, mm, ss;
int T;
int main(){
int n, c;
cin >>n >>c;
int Ans = 0;
for(int x,y,i=1; i<=n; i++) {
scanf("%d:%d",&x,&y);
Ans += x * 60;
Ans += y;
}
Ans -= c * (n - 1);
printf("%02d:%02d:%02d\n", Ans / 3600,(Ans % 3600) / 60, Ans % 60);
}
D
思路: 每一行中通过交换的最大值 记录交换次数 按每行的交换次数排序 取前一半
代码:
#include<bits/stdc++.h>
#define For(i, s, e) for(int i = s; i < e; i++)
#define For_(i, s, e) for(int i = s; i > e; i++)
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
#define ll long long
int sum[1001];
int w,p;
int ans;
int cnt;
int main(){
sd2(w, p);
For(i, 0, w){
int c = 0;
priority_queue<int> q;
int ic;
sd1(ic);
For(j, 1, p){
int t2;
sd1(t2);
q.push(t2);
}
while(ic <= q.top()){
int t3 = q.top();
q.pop();
ic++;
c++;
q.push(t3-1);
}
sum[i] = c;
}
int ans = 0;
sort(sum , sum + w);
for(int i = 0; i < w/2+1; i++){
ans += sum[i];
}
cout << ans << endl;
}
K Move & Meet
思路 : 由题意 分情况讨论即可 记录两点距离 可用x_,y_标记方向
代码:
#include<bits/stdc++.h>
#define For(i, s, e) for(int i = s; i < e; i++)
#define For_(i, s, e) for(int i = s; i > e; i++)
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
#define ll long long;
int main(){
LL x1, x2, y1, y2, d1, d2;
LL xx, yy, x_, y_;
cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
if(x1 - x2 >= 0)
x_ = -1;
else x_ = 1;
if(y1 - y2 >= 0)
y_ = -1;
else y_ = 1;
LL x = abs(x1 - x2);
LL y = abs(y1 - y2);
LL s = x + y;
LL d = d1 + d2;
if(s > d || (d - s) % 2 != 0){
cout << "impossible" << endl;
}
else{
if(d1 < s){
if(d1 <= x){
xx = x1 + d1 * x_;
yy = y1;
}
else{
xx = x2;
yy = (d1 - x) * y_ + y1;
//cout << d1 << x << (d1 - x) * y_;
}
}
else{
if((d1 - s) % 2 == 0){
xx = x2;
yy = y2;
}
else{
xx = x2 + 1;
yy = y2;
}
}
}
printf("%lld %lld\n", xx, yy);
}