German Collegiate Programming Contest 2019总结

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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值