Educational Codeforces Round 81 (Rated for Div. 2)

南笙酒味 提交于 2020-01-31 11:54:02

结果:2350/9339

在这里插入图片描述
C挂了,恶心人啊,cf电脑一直登不上,还是手机查的,这场比赛好气啊;
在这里插入图片描述

A. Display The Number

解法:若n为偶数,输出n/2个1;若n为奇数,输出7和(n-3)/2个1.
WA点:7放后面WA了一发。
ACODE:

/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll a[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t,n;
	cin>>t;
	 while(t--)
	 {
	 	cin>>n;
	 	if(n&1){
	 		int tmp = n-3;
	 		cout<<7<<string(tmp/2,'1')<<endl;
		 }else{
		 	cout<<string(n/2,'1')<<endl;
		 }
	 }
  	return 0;
}

Infinite Prefixes

解法:定义pre[i]表示长度为i的前缀平衡值,最后得到的前缀为k(k>=0) 个完整串和长度为i(0~n-1)的字串组成,遍历i从0至n-1,分情况讨论:
WA点:pre[n] = abs(pre[n]) 产生副作用WA了2发。
ACODE:

/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll pre[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll t,n,x,cnt0,cnt1;
	string s;
	cin>>t;
	while(t--){
		cin>>n>>x>>s;
		cnt0=0,cnt1=0;
		fill(pre,0);
		rep(i,0,n){
			pre[i] = cnt0-cnt1;
			(s[i]=='0'?cnt0++:cnt1++);
		}
		pre[n] = cnt0-cnt1;
		ll f = 0,ans = 0;
		ll N = pre[n] ;
		rep(i,0,n){
			ll left = x-pre[i];
			pre[n] = N;
			if(left*pre[n]<0){
				;
			}else{
				
				left = abs(left);
				pre[n] = abs(pre[n]);
				if(pre[n]==0){
					if(left==0){
						cout<<-1<<endl;
						f = 1;
						break; 
					}else{
						; 
					} 
				}else{
					if(left%pre[n]==0){
						ans++;
					}
				}
			}
		}
		if(f)continue;
		cout<<ans<<endl;
	}
  	return 0;
}

Obtain The String

解法:保存每个字符在s中的位置数组,遍历字符串t,看当前字符在前一字符的位置后面是否存在。
WA点:没有用while找位置,而是单纯从0开始判断。
ACODE:

/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
int a[26];
int b[26];
int c[26];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T,n,m,f;
	string s,t;
	cin>>T;
	while(T--){
		cin>>s>>t;
		fill(a,0);
		fill(b,0);
		fill(c,0);
		unordered_map<char,vector<int> > P;
		n = s.size(),m = t.size();
		f = 0;
		rep(i,0,n){
			a[s[i]-'a']++;
			P[s[i]].pb(i);
		}
		rep(i,0,m){
			if(a[t[i]-'a']==0){
				f=1;
				cout<<-1<<endl;
				break;
			}
		}
		if(f)continue;
		int i=0,ans=1;
		int pre = -1;
		while(i<m){
			while(c[t[i]-'a']<(int)P[t[i]].size()&&P[t[i]][c[t[i]-'a']]<=pre)c[t[i]-'a']++;
			if(c[t[i]-'a']<(int)P[t[i]].size()){
				pre = P[t[i]][c[t[i]-'a']];
				c[t[i]-'a']++;
				i++; 
			}else{
				ans++;
				fill(c,0);
				pre = -1;
			}
		}
		cout<<ans<<endl;
	}
  	return 0;
}
 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!