Educational Codeforces Round 98 (Rated for Div. 2) A ~D

A:
交错走,当x==y则直接走x + y 否则走 2*max(x,y)-1.

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int mod = 2013;
const int N = 1e5+10;
 
signed main(){
	IOS
    #ifdef ddgo
		freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
    #endif
	
	int tt; cin>>tt;
	while(tt --){
		int a,b; cin>>a>>b;
		if(a == b) cout<<a+b<<endl;
		else cout<<2*max(a,b)-1<<endl;
	}
	
    return 0;
}

B:

大意,对于序列的任意一个数,全部分给其它n-1个数,使得每一个数都相同,我们至少需要额外补多少数。
思路:
不能减少,只能增加。(除了最大那个数) 任取一个,分配给其它的数的时候,其它数一定要满足每一个数都是最大的数。而取最大的那个数的处理被这些情况包含。
当然,上述情况只适用于当这个序列的sum小于等于ma * (n-1)时 。 而对于sum > ma*(n-1)时,我们需要扩大ma的范围。 即可以得到公式
res = (ma+k) * (n-1) - sum.
在上面一个数中,k是未知的,因为res是大于等于0的,所以我们可以直接求出最小的大于0的k,k<0则k等于0,因为不能减少。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int mod = 998244353;
const int N = 1e5+10;

int a[N];

signed main(){
	IOS
    #ifdef ddgo
		freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
    #endif
	
	int tt; cin>>tt;
	while(tt --){
		int n,res = 0,ma = -INF; cin>>n;
		for(int i=0;i<n;i++) cin>>a[i],res += a[i],ma = max(ma,a[i]);
		int k = (res+n-2)/(n-1) - ma;
		if(k < 0) k = 0;
		cout<<((ma+k)*(n-1)-res)<<endl;
	}
	 
    return 0;
}

C:
一个(和一个)抵消,一个[和]抵消。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int mod = 2013;
const int N = 1e5+10;
 
signed main(){
	IOS
    #ifdef ddgo
		freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
    #endif
	
	int tt; cin>>tt;
	while(tt --){
		int cnt1 = 0,cnt2 = 0,res = 0;
		string s; cin>>s;
		for(int i=0;i<(int)s.size();i++){
			if(s[i] == '(') cnt1++;
			else if(s[i] == '[') cnt2++;
			else if(s[i] == ')'){
				if(cnt1 > 0){
					res ++;
					cnt1 --;
				}
			}else{
				if(cnt2 > 0){
					res ++;
					cnt2 --;
				}
			}
		}
		cout<<res<<endl;
	}
	
    return 0;
}

D:

题目大意:
给你n+2个城市,要求,给1~n的城市的设置信号塔,使得,0,n+1不能接收到信号,且1 ~ n的城市都有且仅接收到1个信号。
思路,对于分母,选与不被选都是1/2的概率,所以分母即为qmi(2,n).

分子,考虑一个序列0 1 2 3 4 5 6 7 8 9 10 11. 即n为10.

设f(x) 表示 1~x 的选取方案。那么,
1:当在10上设置1个长度为1的信号塔时,此时的方案数位f(9)。
2:当在10上不设置时,则只能由前面的传送信号给10,假设是9号位置传送,则8,9,10都有信号了,对于8这个点位,我们可以把它看和1一样,但是长度段一点,此时方案数位f(7)。那假设是8号位置传送,则同理,方案数为f(5) … f(1).
这是对于n为偶数的情况,当n为奇数的情况时,最后会有一项时f(0),我们令f(0) = 1.

这样我们就可以得到两个式子,
n为偶数 f(n-1) + … + f(n-3) + …+f(1)
n为奇数 f(n-1) + … + f(n-3) + …+f(0)
对上式化简,得到 res = Fib(n),斐波那契的第n项。

当n为奇数
Fib(n) = Fib(n-1) + Fib(n-2) ->Fib(n-1) + Fib(n-3) + Fib(n-4) -> Fib(n-1) + Fib(n-3) + Fib(n-5) + Fib(n-6) … 最后会到 f(1)
当n为偶数
Fib(n) = Fib(n-1) + Fib(n-2) ->Fib(n-1) + Fib(n-3) + Fib(n-4) -> Fib(n-1) + Fib(n-3) + Fib(n-5) + Fib(n-6) … 最后会到 f(0)

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int mod = 998244353;
const int N = 1e5+10;

int qmi(int a,int b){
	int res = 1;
	while(b){
		if(b & 1) res = res * a % mod;
		a = a*a % mod;
		b >>= 1;
	}
	return res;
}
 
int f(int n){
	int a = 1,b = 1;
	for(int i=3;i<=n;i++){
		int t = (a+b)%mod;
		a = b;
		b = t;
	}
	return b;
}
 
signed main(){
	IOS
    #ifdef ddgo
		freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
    #endif
	
	int n; cin>>n;
	int y = qmi(qmi(2,n),mod-2);
	cout<<(f(n)%mod*y%mod)<<endl;
		
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值