【CodeForces】Round #436

A FairGame

//Fair Game
//一道裸的模拟题而已
//二十分钟了。。。mdzz
//虽然英文蛋疼
#include<iostream>
#include<map>
using namespace std;
map<int, int>ma;
int a, b;
int x, y;
int main(){
	int n;  cin>>n;
	for(int i = 1; i <= n; i++){
		int t;  cin>>t;  ma[t]++;
	}
	if(ma.size() != 2){ cout<<"NO\n"; return 0;}
	int co = 0;
	for(map<int,int>::iterator it = ma.begin(); it != ma.end(); it++){
		if(co++==0){ a = it->first; x = it->second; }
		else { b = it->first; y = it->second; }
	}
	if(x!=y || a==b)cout<<"NO\n";
	else cout<<"YES\n"<<a<<" "<<b<<"\n";
	return 0;
}

B

//第二题反而开始灌水了,十分钟都没有就搞定了??,结果WA。。。
//两个智障BUG改了10分钟,我还差点写了对拍
#include<iostream>
#include<set>
#include<string>
#include<cctype>
using namespace std;
set<char>Set;
int main(){
	int n;  cin>>n;
	string s;  cin>>s;
	int t = 0, ans = 0;
	for(int i = 0; i < n; i++){//BUG1QAQ字符串为什么会从1开始呢。。。
		if(isupper(s[i])){ ans = max(ans, t); t = 0; Set.clear();}
		else if(islower(s[i])){
			if(Set.count(s[i]))continue;
			else { Set.insert(s[i]); t++; }
		}
	}
	//BUG2出来的时候要更新,万一没有大写字母呢
	ans = max(ans, t);
	cout<<ans<<"\n";
	return 0;
}

C

//WA
//数据范围有点方了,先试试模拟会不会T, 专业打表写了半小时我去。。。
//打表到这份上也是没谁了,然而还是炸了,,第六个点就WA,,然而,真的,没法改了。。。
#include<iostream>
using namespace std;
int main(){
	int a, b, f, k;
	cin>>a>>b>>f>>k;
	int lx = f, rx = a-f;
	int ln = f*2, rn = (a-f)*2;
	int dir = 0, res = b-lx;//dir为0朝右边,
	int i = 0, ans = 0;
	if(res < 0){
		cout<<"-1\n";  return 0;
	}
	while(i < k-1){
		if(res < 0){
			cout<<"-1\n";  return 0;
		}
		if(!dir){
			if(res >= rn){
				dir = 1;  res -= rn;  i++;  continue;
			}else{
				dir = 1;  res = b-rn;  i++;  ans++;
			}
			if(res < 0){
				cout<<"-1\n";  return 0;
			}
		}
		else{
			if(res >= ln){
				dir = 0; res -= ln; i++; continue;
			}else{
				dir = 0; res=b-ln; i++; ans++;
			}
			if(res < 0){
				cout<<-1<<"\n";  return 0;
			}
		}
	}
	if(res < 0){
		cout<<"-1\n";  return 0;
	}
	if(i == k-1){
		if(!dir && res < rx)ans++;
		if(dir && res < lx)ans++;
	}
	if(res < 0){
		cout<<"-1\n";  return 0;
	}
	cout<<ans<<"\n";
	return 0;
}
//AC
//正确的打表姿势
#include<iostream>
using namespace std;
int main(){
	int a, b, f, k;
	cin>>a>>b>>f>>k;
	int dir = 0, res = b-f, ans = 0;
	if(res < 0){ cout<<-1<<"\n"; return 0; }
	while(k-->0){
		int l;
		if(!dir){
			if(k == 0)l = a-f;
			else l = (a-f)<<1;
		}else{
			if(k == 0)l = f;
			else l = f<<1;
		}
		if(res < l){
			ans++;
			res = b;
		}
		res -= l;
		dir = !dir;
		if(res < 0){ cout<<-1<<"\n"; return 0; }
	}
	cout<<ans<<"\n";
	return 0;
}

D

//WA
//贪心失败。。sort失败,,,现在手写排序已经来不及了。。。
#include<iostream>
#include<algorithm>
#include<set>
#define maxn 200010
using namespace std;
set<int>s;
int a[maxn], b[maxn], c[maxn];//b记录值i第一次在a中出现的位置
bool cmp(int a, int b){
	//if(c[a]&&c[b]) return a < b;
}
int main(){
	int n;  cin>>n;
	int t, ans = 0, minv = 1;
	for(int i = 1; i <= n; i++){
		cin>>t;  a[i] = t;
		if(!s.count(t)){ s.insert(t); b[t] = i; continue; }
		else{
			if(minv >= *s.begin()){
				for(set<int>::iterator it = s.begin()++; it != s.end(); it++){
					if(minv < *it)break;
					else minv = (*it)+1;
				}
			}
			a[b[t]] = minv;
			c[minv] = 1;
			b[t] = i;
			minv++;
			ans++;
		}
	}
	sort(a+1,a+n+1, cmp);
	cout<<ans<<"\n";
	for(int i = 1; i <= n; i++)
		cout<<a[i]<<" ";
	cout<<"\n";
	return 0;
}
posted @ 2018-12-09 16:29  gwj1139177410  阅读(214)  评论(0编辑  收藏  举报
选择