博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

9.28 正睿普及3


2018.9.28 正睿普及3

时间:(实际)
期望得分:100+100+100+...100?
实际得分:100+96+100+0

比赛链接

D这种模拟还是趁早放弃好/zj
放代码自己体会/zj

C题是搞笑的吧

过几天能交了再改

A

题目链接

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=1e6+5;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	LL a=read(),b=read(),c=read();
	if(a==1||b==1||c==1) return putchar('0'),0;
	LL ans=2ll*a*b;
	ans+=2ll*(b*c-b*2);
	ans+=2ll*(a*c-c*2-std::max(0ll,a-2)*2);
	printf("%lld\n",a*b*c-ans);

	return 0;
}

B

题目链接

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
typedef long long LL;

int opt[7];
LL a,b,c,d,Ans;

inline int read()
{
	int now=0,f=1;register char c=gc();
	for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now*f;
}
void DFS(int x)//懒得换double怎么办 
{// 1+ 2- 3* 4/
	if(x>3)
	{
		LL res=0,tmp;
		if(opt[1]==1||opt[1]==2)
		{
			if(opt[2]==1||opt[2]==2)
			{
				if(opt[3]==1||opt[3]==2)
					res=a+(opt[1]==1?b:-b)+(opt[2]==1?c:-c)+(opt[3]==1?d:-d);
				else
				{
					if(opt[3]==4 && c%d) return;
					tmp=opt[3]==3?c*d:c/d;
					res=a+(opt[1]==1?b:-b)+(opt[2]==1?tmp:-tmp);
				}
			}
			else
			{
				if(opt[2]==4 && b%c)
				{
					if(opt[3]==3 && !(b*d%c)) Ans=std::min(Ans,std::abs(a+(opt[1]==1?1ll:-1ll)*b*d/c));
					return;
				}
				tmp=opt[2]==3?b*c:b/c;
				if(opt[3]==1||opt[3]==2)
					tmp+=(opt[3]==1?d:-d);
				else
				{
					if(opt[3]==4 && tmp%d) return;
					tmp=(opt[3]==3?tmp*d:tmp/d);
				}
				res=opt[1]==1?a+tmp:a-tmp;
			}
		}
		else//*/
		{
			if(opt[1]==4 && a%b)
			{
				if(opt[2]==3)
				{//mmp
					if(opt[3]==3)
						if(!(a*c*d%b)) Ans=std::min(Ans,std::abs(a*c*d/b));
						else return;
					else if(opt[3]==4)
						if(!(a*c%(b*d))) Ans=std::min(Ans,std::abs(a*c/b/d));
						else return;
					else if(!(a*c%b)) Ans=std::min(Ans,std::abs(a*c/b+(opt[3]==1?d:-d)));
					else return;
				}
				else if(opt[2]==4)
				{
					if(opt[3]==3)
						if(!(a*d%(b*c))) Ans=std::min(Ans,std::abs(a*d/b/c));
						else return;
					else return;
				}
				return;
			}
			tmp=opt[1]==3?a*b:a/b;
			if(opt[2]==1||opt[2]==2)
			{
				if(opt[3]==1||opt[3]==2)
					res=tmp+(opt[2]==1?c:-c)+(opt[3]==1?d:-d);
				else
				{
					if(opt[3]==4 && c%d) return;
					res=tmp+(opt[2]==1?(opt[3]==3?c*d:c/d):-(opt[3]==3?c*d:c/d));
				}
			}
			else
			{
				if(opt[2]==4 && tmp%c)
				{
					if(opt[3]==3 && !(tmp*d%c)) Ans=std::min(Ans,std::abs(tmp*d/c));
					else return;
					return;
				}
				tmp=opt[2]==3?tmp*c:tmp/c;
				if(opt[3]==1||opt[3]==2)
					res=opt[3]==1?tmp+d:tmp-d;
				else
				{
					if(opt[3]==4 && tmp%d) return;
					res=opt[3]==3?tmp*d:tmp/d;
				}
			}
		}
//		printf("%d %d %d %I64d\n",opt[1],opt[2],opt[3],res);
		Ans=std::min(Ans,std::abs(res));
		return;
	}
	for(int i=1; i<=4; ++i)
		opt[x]=i, DFS(x+1);
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	a=read(),b=read(),c=read(),d=read();
	Ans=std::abs(a+b+c+d), DFS(1), printf("%lld\n",Ans);

	return 0;
}

C

题目链接

#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#define gc() getchar()
#define MAXIN 300000
//#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5;

int n,tot,dep[N],fa[N];
LL Ans;
std::vector<int> e[N];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
inline void AE(int u,int v)
{
	e[u].push_back(v), e[v].push_back(u);
}
bool cmp(int x,int y)
{
	return dep[x]<dep[y];
}
void DFS1(int x)
{
	for(int i=0,l=e[x].size(),v; i<l; ++i)
		if((v=e[x][i])!=fa[x])
			fa[v]=x, dep[v]=dep[x]+1, DFS1(v);
}
void DFS2(int x)
{
	static int Time=0;

	Ans+=tot-Time, ++Time;
//	std::sort(e[x].begin(),e[x].end(),cmp);
	for(int i=0,l=e[x].size(),v; i<l; ++i)
		if((v=e[x][i])!=fa[x]) DFS2(v), ++Time;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	n=read(), tot=2*n-2;
	for(int i=1; i<n; ++i) AE(read(),read());
	DFS1(1), DFS2(1);
	printf("%lld\n",Ans);

	return 0;
}

D

题目链接


考试代码

D

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=1e5+7;

int n;
char s[N];

int Nxt_Oct(int now,int &p)
{
	if(now>n) {p=now; return 0;}
	int nxt,res=0;
	while(s[now]=='O')
	{
		nxt=now+1,res=0;
		while(nxt<=n && isdigit(s[nxt])) res=res*10+s[nxt]-'0', ++nxt;
		now=nxt;
	}
	p=now;
	return res;
}
void Nxt_Vol(int now,int &p,int &vol,int &ans)
{
	int nxt=now+1,res=0,tmp=now;
	while(s[now]=='V')
	{
		nxt=now+1,res=0;
		while(nxt<=n && isdigit(s[nxt])) res=res*10+s[nxt]-'0', ++nxt;
		tmp=now, now=nxt;
	}
	p=now;
	for(int i=now; i<=n; ++i)
		if(isalpha(s[i]) && s[i]!='V' && s[i]!='O') {ans+=now-tmp; break;}
		else if(i==n) p=n+1;
	if(res!=vol) vol=res;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	while(scanf("%s",s+1),s[1]!='*')
	{
		n=strlen(s+1), s[n+1]='$';

		int oct=4,real=4,vol=100;//volume
		int ans=0,now=1;
		for(; now<=n; )
		{
//			printf("n:%d now:%d oct:%d real:%d vol:%d ans:%d\n",n,now,oct,real,vol,ans);
			if(s[now]=='V')
			{
				int nxt=now+1,res=0,tmp=now;
				while(s[now]=='V')
				{
					nxt=now+1,res=0;
					while(nxt<=n && isdigit(s[nxt])) res=res*10+s[nxt]-'0', ++nxt;
					tmp=now, now=nxt;
				}
				if(nxt>n) break;
				if(res!=vol) vol=res, ans+=nxt-tmp;
			}
			else if(s[now]=='O')
			{
				int nxt,res=oct;
				while(s[now]=='O')
				{
					nxt=now+1,res=0;
					while(nxt<=n && isdigit(s[nxt])) res=res*10+s[nxt]-'0', ++nxt;
					now=nxt;
				}
				if(nxt>n) break;
				if(std::abs(oct-res)>1)
				{
					if(res>oct) ans+=res-oct-1, oct=res-1;
					else ans+=oct-res-1, oct=res+1;
				}
				real=res;
			}
			else if(real==oct)
			{
				if(now+1<=n && s[now]=='B' && s[now+1]=='+')
				{
					int nxt=now+2,tm=1;
					while(nxt+1<=n && s[nxt]=='B' && s[nxt+1]=='+') nxt+=2, ++tm;
					now=nxt;
					if(tm==1)
					{
						if(s[now]!='O'&&s[now]!='V') ;//还有bug mmp 
						else if(s[now]!='O')
						{
							Nxt_Vol(now,now,vol,ans);
							if(now>n) now=n+1;
						}

						if(s[now]=='O')
						{
							int tmp,nxtoct=Nxt_Oct(now,tmp);
							now=tmp;
							while(now<=n && s[now]=='V')
							{
								Nxt_Vol(now,now,vol,ans);
								if(now>n) now=n+1;
								if(s[now]=='O')
									nxtoct=Nxt_Oct(now,tmp), now=tmp;
							}
							if(tmp>n) ans+=2;
							else if(nxtoct>oct)
							{
								ans+=2, ++oct;
								real=nxtoct;
								if(std::abs(oct-real)>1)
								{
									if(real>oct) ans+=real-oct-1, oct=real-1;
									else ans+=oct-real-1, oct=real+1;
								}
							}
							else ans+=2;
						}
						else ans+=2;
					}
					else ans+=tm+1, ++oct;
				}
				else if(now+1<=n && s[now]=='C' && s[now+1]=='-')
				{
					int nxt=now+2,tm=1;
					while(nxt+1<=n && s[nxt]=='C' && s[nxt+1]=='-') nxt+=2, ++tm;
					now=nxt;
					if(tm==1)
					{
						if(s[now]!='O'&&s[now]!='V') ;
						else if(s[now]!='O')
						{
							Nxt_Vol(now,now,vol,ans);
							if(now>n) now=n+1;
						}

						if(s[now]=='O')
						{
							int tmp,nxtoct=Nxt_Oct(now,tmp);
							now=tmp;
							while(now<=n && s[now]=='V')
							{
								Nxt_Vol(now,now,vol,ans);
								if(now>n) now=n+1;
								if(s[now]=='O')
									nxtoct=Nxt_Oct(now,tmp), now=tmp;
							}
							if(tmp>n) ans+=2;
							else if(nxtoct<oct)
							{
								ans+=2, --oct;
								real=nxtoct;
								if(std::abs(oct-real)>1)
								{
									if(real>oct) ans+=real-oct-1, oct=real-1;
									else ans+=oct-real-1, oct=real+1;
								}
							}
							else ans+=2;
							now=tmp;
						}
						else ans+=2;
					}
					else ans+=tm+1, --oct;
				}
				else
				{
					while(now<=n && ((s[now]=='+'||s[now]=='-')||((s[now]!='V' && s[now]!='O' && (now==n||s[now]!='C'||s[now+1]!='-') && (now==n||s[now]!='B'||s[now+1]!='+')))))
//						printf("Loop:%d %d %d\n",ans,now,n),
						++ans, ++now;
				}
			}
			else if(real>oct)
			{
				int tm=0;
				while(now+1<=n && s[now]=='C' && s[now+1]=='-')
					++tm, now+=2;
				ans+=tm;

				if(s[now]!='O'&&s[now]!='V') ;
				else if(s[now]!='O')
				{
					Nxt_Vol(now,now,vol,ans);
					if(now>n) now=n+1;
				}

				if(s[now]=='O')
				{
					int tmp,nxtoct=Nxt_Oct(now,tmp);
					if(tmp>n) ;
					else// if(nxtoct<oct)
					{
						real=nxtoct;
						if(std::abs(oct-real)>1)
						{
							if(real>oct) ans+=real-oct-1, oct=real-1;
							else ans+=oct-real-1, oct=real+1;
						}
					}
					now=tmp;
				}
				else if(now<=n) ++ans, ++oct;
			}
			else if(real<oct)
			{
				int tm=0;
				while(now+1<=n && s[now]=='B' && s[now+1]=='+')
					++tm, now+=2;
				ans+=tm;

				if(s[now]!='O'&&s[now]!='V') ;
				else if(s[now]!='O')
				{
					Nxt_Vol(now,now,vol,ans);
					if(now>n) now=n+1;
				}

				if(s[now]=='O')
				{
					int tmp,nxtoct=Nxt_Oct(now,tmp);
					if(tmp>n) ;
					else// if(nxtoct<oct)
					{
						real=nxtoct;
						if(std::abs(oct-real)>1)
						{
							if(real>oct) ans+=real-oct-1, oct=real-1;
							else ans+=oct-real-1, oct=real+1;
						}
					}
					now=tmp;
				}
				else if(now<=n) ++ans, --oct;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
posted @ 2018-09-29 06:47  SovietPower  阅读(114)  评论(0编辑  收藏  举报