Codeforces Round #689 (Div. 2, based on Zed Code Competition)解题报告

a.

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		for(int i = 0;i < n;i++){
			if(i % 3 == 0)
				cout<<'a';
			else if(i %3 == 1)
				cout<<'b';
			else 
				cout<<'c'; 
		}
		cout<<endl;
	}
	return 0;
}

b.复杂度n^3

 	#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 500 + 10;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
char g[N][N];
int l[N][N],r[N][N],len[N][N];
ll ans;
int n,m;
void dfs(int i,int j,int length){
	if(len[i][j] >= length  + 2){
		ans++;
		if(i + 1 <= n)dfs(i + 1,j,length  + 2);
	}
}
void solve(){

	cin>>n>>m;
	ans = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 2;j <= m + 1;j++)
			l[i][j] = r[i][j] = len[i][j]= 0;
	}
	for(int i = 1;i <= n;i++){
		cin>>(g[i] + 2);
	}
	for(int i = 1;i <= n;i++){
		for(int j = 2;j <= m + 1;j++){
			l[i][j] = g[i][j - 1] == '*'?1 + l[i][j - 1]:0;
			//cout<<l[i][j]<<" ";
		}
		//cout<<endl;
		for(int j = m  + 1;j >= 2;j--){
			r[i][j] = g[i][j + 1] == '*'?1 + r[i][j + 1]:0; 
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 2;j <= m + 1;j++){
			len[i][j] = g[i][j] == '*'?2 * min(l[i][j],r[i][j]) + 1:0;
			//cout<<len[i][j]<<" ";
		}
		//cout<<endl;
	}
	for(int i = 1;i <= n;i++){
		for(int j = 2;j <= m + 1;j++){
			if(g[i][j] == '*'){
				ans++;
				if(i < n)dfs(i + 1,j,1);
			}
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

c、

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int a[N];
void solve(){
	double remain = 1.0;
	int n,m;
	cin>>n>>m;
	int maxn = 0;
	for(int i = 1;i <= n;i++){
		cin>>a[i];
		if(a[i] != i)maxn = i;
	}
	double ans = 0;
	for(int i = 1;i <= m;i++){
		int x;
		double p;
		cin>>x>>p;
		if(x >= maxn){
			ans += remain * p;
			remain = remain * (1 - p);
		}
	}
	if(maxn > 0)
		printf("%.6f\n",ans);
	else 
		printf("%.6f\n",1.0);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

d、

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read(){
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int n,q;
ll a[N],sum[N];
void dfs(int l,int r,set<ll>& s){
	s.insert(sum[r] - sum[l - 1]);
	ll mid_n = (a[l] + a[r]) >> 1;
	int mid =  upper_bound(a + l,a + 1 + r,mid_n) - a;
	if(l<= mid - 1 && mid - 1 != r)dfs(l,mid - 1,s);
	if(mid <= r)dfs(mid,r,s);
}
void solve(){
	cin>>n>>q;
	for(int i = 1;i <= n;i++){
		cin>>a[i];
	}
	sort(a + 1,a + 1 + n);
	for(int i = 1;i <= n;i++){
		sum[i] = sum[i - 1] + a[i];
	}
	set<ll> s;
	dfs(1,n,s);
	for(int i = 1;i <= q;i++){
		int x;
		cin>>x;
		bool f = (s.find(x) != s.end());
		if(f)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

EF明天再补叭,先碎了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值