AtCoder Beginner Contest 319 - C(模拟题) D(二分答案) E(规律题)

A 模拟题
B 读懂题意即可

C - False Hope

题意
给定一个 $3 \times 3 $ 的矩阵。
以一个随机的顺序先后看这 9 个数,如果说某一行或者某一列或者某一对角线上的三个数看到的先后顺序满足先看到相同的两个数,再看到不同的一个数,则此次观察定义为不高兴的观察。
问你观察不是不高兴的概率

思路
因为随机查看的方式最多只有 9!种,所以直接遍历所有情况判断每种情况是否成立即可

代码

//>>>Qiansui
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x, y, sizeof(x))
#define debug(x) cout << #x << " = " << x << '\n'
#define debug2(x,y) cout << #x << " = " << x << " " << #y << " = "<< y << '\n'
//#define int long long

using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
/*

*/
const int maxm = 2e5 + 5, inf = 0x3f3f3f3f, mod = 998244353;
int p[10], t[10];
vector<vector<int>> a = {
	{1, 2, 3}, {4, 5, 6}, {7, 8, 9},
	{1, 4, 7}, {2, 5, 8}, {3, 6, 9},
	{1, 5, 9}, {3, 5, 7}
};

void solve(){
	for(int i = 1; i <= 9; ++ i){
		cin >> p[i];
		t[i] = i;
	}
	int cnt = 0, tot = 0;
	do{
		++ tot;
		for(auto c : a){
			sort(c.begin(), c.end(), [&](int x, int y){
				return t[x] < t[y];
			});
			if(p[c[0]] == p[c[1]] && p[c[1]] != p[c[2]]){
				++ cnt; break;
			}
		}
	}while(next_permutation(t + 1, t + 10));
	cout << fixed << setprecision(15) << 1.0 * (tot - cnt) / tot << '\n';
	return ;
}

signed main(){
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int _ = 1;
	// cin >> _;
	while(_ --){
		solve();
	}
	return 0;
}

D - Minimum Width

思路
二分答案

代码

//>>>Qiansui
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x, y, sizeof(x))
#define debug(x) cout << #x << " = " << x << '\n'
#define debug2(x,y) cout << #x << " = " << x << " " << #y << " = "<< y << '\n'
//#define int long long

using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
/*

*/
const int maxm = 2e5 + 5, inf = 0x3f3f3f3f, mod = 998244353;
ll n, m, l[maxm], ml;

bool check(ll x){
	int cnt = 0;
	ll t = 0;
	for(int i = 1; i <= n; ++ i){
		if(t == 0){
			t += l[i];
		}else{
			if(t + 1 + l[i] > x){
				++ cnt;
				t = l[i];
			}else t += 1 + l[i];
		}
	}
	if(t) ++ cnt;
	if(cnt <= m) return true;
	else return false;
}

void solve(){
	cin >> n >> m;
	ll mm = 0;
	for(int i = 1; i <= n; ++ i){
		cin >> l[i];
		ml += l[i];
		ml += (i > 1);
		mm = max(mm, l[i]);
	}
	ll x = mm, y = ml, mid;
	while(x <= y){
		mid = (x + y) >> 1;
		if(check(mid)) y = mid - 1;
		else x = mid + 1;
	}
	cout << x << '\n';
	return ;
}

signed main(){
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int _ = 1;
	// cin >> _;
	while(_ --){
		solve();
	}
	return 0;
}

E - Bus Stops

题意
高桥想从自己家去往青木家
从高桥家到车站 1 需要消耗时间 x;从车站 n 到青木家需要消耗时间 y
对于任意 $i \in [1, n - 1] $,搭乘从车站 i 到车站 i + 1 的车需要消耗时间 \(t_i\),且该车 i 的发车时间为 \(p_i\) 的倍数(保证 $1 \le p_i \le 8 $)
给你 q 次询问,每次问你高桥从时刻 t 从家里出发,最早什么时候能到青木家

思路
参考思路

首先观察到“(保证 $1 \le p_i \le 8 $)”,所以可以知道的是,在 \(lcm \{ p_1, p_2, ..., p_{n - 1} \}\) 时间后,所有车站的发车状态相同,即周期为 \(lcm \{ p_1, p_2, ..., p_{n - 1} \}\)

那么周期最大为 840,故可以先预处理出周期内所有出发时间的所需最小消耗时间,再对每个询问进行处理

对于每一个出发时间,$O(n) $ 扫一遍所有车站即可,这里遵循有车即上,无车等最近车的原则。

具体细节见代码

代码

//>>>Qiansui
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x, y, sizeof(x))
#define debug(x) cout << #x << " = " << x << '\n'
#define debug2(x,y) cout << #x << " = " << x << " " << #y << " = "<< y << '\n'
//#define int long long

using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
/*

*/
const int maxm = 2e5 + 5, inf = 0x3f3f3f3f, mod = 998244353;

void solve(){
	ll n, x, y;
	cin >> n >> x >> y;
	vector<ll> p(n), t(n);
	ll l = 1;
	for(int i = 1; i < n; ++ i){
		cin >> p[i] >> t[i];
		l = lcm(l, p[i]);
	}
	vector<ll> ans(l);
	for(int i = 0; i < l; ++ i){
		ans[i] = i + x;
		for(int j = 1; j < n; ++ j){
			ans[i] += t[j] + (p[j] - ans[i] % p[j]) % p[j];
		}
		ans[i] += y - i;
	}
	int q;
	cin >> q;
	while(q --){
		ll t; cin >> t;
		cout << t + ans[t % l] << '\n';
	}
	return ;
}

signed main(){
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int _ = 1;
	// cin >> _;
	while(_ --){
		solve();
	}
	return 0;
}
posted on 2023-09-10 14:14  Qiansui  阅读(178)  评论(0编辑  收藏  举报