Codeforces Round #730 (Div. 2)【A - D1】

在这里插入图片描述
在这里插入图片描述

A. Exciting Bets

Welcome to Rockport City!

It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y. To make the race more exciting, you can perform two types of operations:

Increase both a and b by 1.
Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.

Note that gcd(x,0)=x for any x≥0.

Input
The first line of input contains a single integer t (1≤t≤5⋅103) — the number of test cases.

The first and the only line of each test case contains two integers a and b (0≤a,b≤1018).

Output
For each test case, print a single line containing two integers.

If the fans can get infinite excitement, print 0 0.

Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.

题意:
给出两个数a,b,可进行①同时加1;②同时减1(a,b都为正数时),求gcd(a, b)的最大值,如果gcd(a,b)可以无限增大,则输出"0,0"

知识点:数学,思维

思路:
①:由gcd(a, b) = gcd(a - b, b)可知,gcd(a + x, b + x) = gcd(a + x - b - x, b + x),即gcd(a + x, b + x) = gcd(a - b, b + x)。所以gcd(a + x, b + x)的最大值就是a - b。
②:求解最小步数,则是min(a到离他最近的最大公因数的倍数的步数,b到离他最近的最大公因数的倍数的步数)

代码:

inline void solve() {
    ll a, b; cin >> a >> b;
    if(a > b) swap(a, b);
    if(a == b) {
        cout << "0 0\n";
        return ;
    }
    ll t = a / (b - a) * (b - a);
    ll t2 = b / (b - a) * (b - a);
    if(b % (b - a)) t2 += (b - a);
    cout << b - a << " " << min(a - t, t2 - b) << endl;
    return ;
}

B. Customising the Track

Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where ai represents the number of traffic cars in the i-th sub-track. You define the inconvenience of the track as, where |x| is the absolute value of x.

You can perform the following operation any (possibly zero) number of times: choose a traffic car and move it from its current sub-track to any other sub-track.

Find the minimum inconvenience you can achieve.

Input
The first line of input contains a single integer t (1≤t≤10000) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤2⋅105).

The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109).

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output
For each test case, print a single line containing a single integer: the minimum inconvenience you can achieve by applying the given operation any (possibly zero) number of times.

题意:
给出一个数字序列a[n],在保证总和不变的前提下可以改变a[i]的大小,使得的值最小

思路:
参照式子,因为|ai - aj|的最小值为0,所以我们需要尽可能使得ai = aj。

知识点:构造,数学,思维

代码:

inline void solve() {
    cin >> n;
    ll sum = 0;
    _for(i, 1, n) cin >> x[i], sum += x[i];
    ll ans = n - (sum % n);
    cout << ans * (sum % n) << endl;
    return ;
}

C: Need for Pink Slips

After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival’s Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don’t draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,

If the item was a Pink Slip, the quest is over, and you will not play any more races.
Otherwise,
If a≤v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
If a>v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,

If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.

Input
The first line of input contains a single integer t (1≤t≤10) — the number of test cases.

The first and the only line of each test case contains four real numbers c, m, p and v (0<c,m,p<1, c+m+p=1, 0.1≤v≤0.9).

Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.

Output
For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip.

Your answer is considered correct if its absolute or relative error does not exceed 10−6.

Formally, let your answer be a, and the jury’s answer be b. Your answer is accepted if and only if

题意:给出概率p1,p2,p3,参数v,每轮以概率抽一个,抽到1或2则p1或p2减去最多v,均分给另外两个,为0时将其移除游戏。重复直到抽到p3,问轮数的期望。

知识点:搜索,模拟

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e-6
double a, b, c, p;
inline double solve(double a, double b) {
	if(a < inf && b < inf) return 0;
	double ans = 0 ;
	if(a > inf) {
		double d = min(a, c);
		if(b >= inf)
			ans += a * (1 + solve(a - d, b + d / 2));
		else  
			ans += a * (1 + solve(a - d, 0));
	}
	if(b > inf) {
		double d = min(b, c) ;
		if(a >= inf)
			ans += b * (1 + solve(a + d / 2, b - d));
		else 
			ans += b * (1 + solve(0, b - d));
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int t; cin >> t;
	while(t--) {
		cin >> a >> b >> p >> c;
		printf("%.15lf\n",1 + solve(a, b)) ;
	}
}

D1: RPD and Rap Sheet (Easy Version)

知识点:构造、交互题

题意:最多猜n次,每一次结果返回0/1,代表错误/正确,有一个未知的初始密码[0,n-1],密码是根据每一次的猜测更改的,更改之前的密码设为x,猜的密码设为y,更改之后的密码设为z。那么x ⊕ z = y.

①:x⊕y=z ==> x⊕z=y
②:猜测的次数等于初始密码的可能情况总数
③:由于没有别的多余信息,我们唯一能够建立的联系便是初始密码与猜测次数的联系,假设初始密码为x-1,我们想办法使得第x次便猜出答案。
④:开始瞎猜测,当初始密码为x时,我们采取下列方式
y = 0, i = 0
y = i ⊕ y i >= 1
第一次y = 0, i = 0, x ==> z = x⊕0 = x
第二次y = 1⊕0 = 1, i = 1, x ==>z = x⊕1;
第三次y = 1⊕2, i = 2, x ==> z = x⊕1⊕1⊕2 = x⊕2

第x - 1次,y = 1⊕2⊕3……⊕x - 1, i = x - 1, x ==>z = x⊕(x - 1)

代码:

#include <bits/stdc++.h>
#define _for(i, a, b) for(register int i = a; i <= b; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll N = 1e7 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f;
ll t, n, m, k;
ll x[N];
unordered_map<ll, ll> mp;

inline void solve() {
    cin >> n >> k; k = 0;
    int cai = 0, now = 4;
    for(int i = 0, s = 0; i < n; i ++) {
    	cout << (s ^ i) << endl;cout.flush();
    	int k; cin >> k;
    	if(k == 1) break;
    	s = i;
    }
    return ;
}

int main() {
    cin >> t;
    while(t--)
        solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

顶白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值