Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3)

链接:#477

A:

#include <bits/stdc++.h>

#define N 102
using namespace std;

int main() {
	int i, n, s, h , m, t = -1;
	cin >> n >> s;
	int a, b;
	a = -s - 1; 
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &h, &m);
		b = h * 60 + m;
		if (b - a >= s * 2 + 2) {
		printf("%d %d", (a + s + 1) / 60, (a + s + 1) % 60);
		break;		
		}
		else {
			a = b;
		}
	} 
	if (i > n) {
		printf("%d %d", (a + s + 1) / 60, (a + s + 1) % 60);	
	}
	return 0;
}

B:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

#define N 100005
using namespace std;
int n;
	
int main() {
	int i, n, A;
	long long  sum = 0;
	int B;
	cin >> n >> A >> B;
	int a[N];
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];	
	}
	sort(a + 1, a + n); 
	int ans = 0;
	i = n - 1;
	while(1) {
		if (a[0] * 1.00 / sum * A >= 1.00 * B) {
			break;	
		}	
		sum -= a[i--];
		ans++;
	}
	cout << ans << endl;
	return 0;
}

C:

#include <iostream>             //梯子一共有三种情况, 在左边,中间,右边。
#include <cstdio>               //  以左端点为基点,  左端点的  左边 和右边(包括中间, 右边)  所以分为两种情况
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define N 100005
using namespace std;

int main() {
	int a[N], b[N]; 
	int n , m, c1, c2, v, i, mi1, mi2, min1, min2;
	scanf("%d%d%d%d%d", &n, &m, &c1, &c2, &v);
	if (c1 != 0) {
		for (i = 0; i < c1; i++) {
			scanf("%d", &a[i]);	
		}
	}
	if (c2 != 0) {
		for (i = 0; i < c2; i++) {
			scanf("%d", &b[i]);	
		}
	} 
	int q;
	cin >> q;
	while (q--) { 
		int mi1 = 1e9 + 2, mi2 = 1e9 + 2; 
		int x1, x2, y1, y2, ma, mb;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2) {
			cout << abs(y1 - y2) << endl;
			continue;	
		}
		ma = lower_bound(a, a + c1, min(y1, y2)) - a;
		mb = lower_bound(b, b + c2, min(y1, y2)) - b;
		if (ma < c1) {
			mi1 = min(mi1, abs(y1 - a[ma]) + abs(y2 - a[ma]));
		}
		if (ma >= 1) {
			mi1 = min(mi1, abs(y1 - a[ma - 1]) + abs(y2 - a[ma - 1]));
		}
		if (mb < c2) {
			mi2 = min(mi2, abs(y1 - b[mb]) + abs(y2 - b[mb]));
		}
		if (mb >= 1) {
			mi2 = min(mi2, abs(y1 - b[mb - 1]) + abs(y2 - b[mb - 1]));
		}
		min1 = mi1 + abs(x1 - x2); 
		min2 = mi2 + (abs(x1 - x2) + v - 1) / v;
		cout << min(min1, min2) << endl;
	}
	return 0;
}
C: 第二种方法,用字符处理输入整数
#include <iostream>             //梯子一共有三种情况, 在左边,中间,右边。  
#include <cstdio>               //  以左端点为基点,  左端点的  左边 和右边(包括中间, 右边)  所以分为两种情况  
#include <map>  
#include <vector>  
#include <queue>  
#include <algorithm>  
#include <climits>  
#include <cstring>  
#include <cmath>  
#include <vector>  
#include <map>  
  
#define N 100005  
using namespace std;  
template<class T>
void read(T &x) {
	x = 0;
	char c = getchar();
	bool flag = 0;
	while(c<'0'||'9'<c) { 
	  if(c == '-') 
		  flag=1;
		c = getchar();
	}
	while('0' <= c && c <= '9') { 
	  x = x * 10 + c - '0';
	  c = getchar();
	}
	if(flag)
	  x = -x;
}
int main() {  
  int a[N], b[N];   
  int n , m, c1, c2, v, i, mi1, mi2, min1, min2;  
  read(n); read(m); read(c1); read(c2); read(v); 
  for (i = 0; i < c1; i++) {  
    read(a[i]);   
  }  
  for (i = 0; i < c2; i++) {  
    read(b[i]);   
  }  
  int q;  
  read(q);  
	while (q--) {   
    int mi1 = 1e9 + 2, mi2 = 1e9 + 2;   
    int x1, x2, y1, y2, ma, mb;  
    read(x1); read(y1); read(x2); read(y2);  
    if (x1 == x2) {  
      cout << abs(y1 - y2) << endl;  
      continue;     
    }  
    ma = lower_bound(a, a + c1, min(y1, y2)) - a;  
    mb = lower_bound(b, b + c2, min(y1, y2)) - b;  
    if (ma < c1) {  
      mi1 = min(mi1, abs(y1 - a[ma]) + abs(y2 - a[ma]));  
    }  
    if (ma >= 1) {  
      mi1 = min(mi1, abs(y1 - a[ma - 1]) + abs(y2 - a[ma - 1]));  
    }  
    if (mb < c2) {  
      mi2 = min(mi2, abs(y1 - b[mb]) + abs(y2 - b[mb]));  
    }  
		if (mb >= 1) {  
      mi2 = min(mi2, abs(y1 - b[mb - 1]) + abs(y2 - b[mb - 1]));  
    }  
    min1 = mi1 + abs(x1 - x2);   
    min2 = mi2 + (abs(x1 - x2) + v - 1) / v;  
    cout << min(min1, min2) << endl;  
  }  
  return 0;  
}  

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值