AtCoder Beginner Contest 338(A~E补题)

文章目录

  • A
  • B
  • C题
  • D题
  • E题

A

签到

#include  
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N=5e5+10;


void solve()
{
	string str;cin>>str;
	bool st=true;
	rep(i,0,str.size()-1)
	{
		if(!i)	
		{
			if(str[i]>='A'&&str[i]<='Z')	continue;
			else
			{
				cout<<"No"<<endl;
				return;
			}
		}
		if(str[i]>='a'&&str[i]<='z')	continue;
		else
		{
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}

int main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
  	int t;
//	cin>>t;
//	while(t--)
	solve();
	return 0;
}

B

签到题

#include  
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N=5e5+10;


void solve()
{
	string str;cin>>str;
	map<char,int>cnt;
	for(auto c:str)	cnt[c]++;
	char c;
	int k=0;
	for(auto it:cnt)
	{
		if(it.y>k)	
		{
			k=it.y;
			c=it.x;
		}
	}
	cout<<c<<endl;
}

int main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
  	int t;
//	cin>>t;
//	while(t--)
	solve();
	return 0;
}

C题

观察到数据范围n只有10,想到去枚举a的数量然后去看b最多能做多少。

#include  
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N=20;
int c[N],a[N],b[N],n;

bool check1(int x)
{
	rep(i,1,n)	if(x*a[i]>c[i])	return false;
	return true;
}

void solve()
{
	cin>>n;
	int sa=0,sb=0,sc=0;
	rep(i,1,n)	cin>>c[i],sc+=c[i];
	rep(i,1,n)	cin>>a[i],sa+=a[i];
	rep(i,1,n)	cin>>b[i],sb+=b[i];
	int ans=0;
	rep(gg,0,1e6)
	{
		if(!check1(gg))	break;
		int kk=1e6; 
		rep(i,1,n)
		{
			if(b[i]==0)	continue;
			int xx=c[i]-a[i]*gg;
			xx/=b[i];
			kk=min(kk,xx);
		} 
		ans=max(ans,gg+kk);
	}	
	cout<<ans<<endl;
}

int main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
//  	int t;
//	cin>>t;
//	while(t--)
	solve();
	return 0;
}

D题

也很巧妙,贡献法的思想。
对于每一个路径计算他对不同断桥产生的贡献。

#include  
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N=1e6+10;

ll n,m,x[N],cf[N];

ll dist(ll x,ll y)
{
	if(x<=y)	return y-x;
	else	return n-(x-y);
}

void add(ll x,ll y,ll d)
{
	if(x<=y)
	{
		cf[x]+=d;
		cf[y]-=d;
	}
	else
	{
		cf[x]+=d;
		cf[n+1]-=d;
		cf[1]+=d;
		cf[y]-=d;
	}
}

void solve()
{
	cin>>n>>m;
	rep(i,1,m)	cin>>x[i];
	rep(i,1,m-1)
	{
		add(x[i],x[i+1],dist(x[i+1],x[i]));
		add(x[i+1],x[i],dist(x[i],x[i+1]));
	}
	ll ans=1e18;
	rep(i,1,n)	cf[i]+=cf[i-1];
	rep(i,1,n)	ans=min(ans,cf[i]);
	cout<<ans<<endl;
}

int main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
  	int t;
//	cin>>t;
//	while(t--)
	solve();
	return 0;
}

E题

#include  
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
#define pb push_back

using namespace std;
const int N=4e5+10;
int cf[N],x[N],y[N];

void solve()
{
	int n;cin>>n;
	rep(i,1,n)
	{
		cin>>x[i]>>y[i];
		if(x[i]>y[i])	swap(x[i],y[i]);
		cf[x[i]]+=1;cf[y[i]+1]-=1;	
	}
	rep(i,1,2*n)	cf[i]+=cf[i-1];
	rep(i,1,n)	
	{
		if(cf[x[i]]!=cf[y[i]])
		{
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;	
}
signed main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
//  	int _;
//	cin>>_;
//	while(_--)
	solve();
	return 0;
}

你可能感兴趣的:(atcode,算法,数据结构,mybatis,django,java,eclipse,spring,boot)