qbxt NOIP2016 模拟题

day1

tile 铺瓷砖

数学

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
    	if(ch=='-') f=-1;
    	ch=getchar();
    }
    while('0'<=ch&&ch<='9'){
    	x=x*10+ch-'0';
    	ch=getchar();
    }
    return x*f;
}
LL T;
LL gcd(LL x,LL y){
	if(y==0) return x;
	else return gcd(y,x%y);
}
LL lcm(LL x,LL y){
	return x/gcd(x,y)*y;
}
int main(){
	freopen("tile.in","r",stdin);
	freopen("tile.out","w",stdout);
	T=read();
	LL a,b,c,d,e,f,g;
	while(T--){
		a=read();b=read();c=read();d=read();
		e=a*d/gcd(b,d);
		f=c*b/gcd(b,d);
		g=lcm(e,f)/e;
		if(a*g%b==0) printf("%lld\n",a*g/b);
		else printf("%lld/%lld\n",a*g/gcd(a*g,b),b/gcd(a*g,b));
	}
	fclose(stdin);fclose(stdout);
	return 0;
}

question 小Y的问题

#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
LL n,x,y,z,num,dg[300000],fl[300000][4],ans;
LL ff[300000][4],sum,flagg;
LL head[1500000],next[1500000],to[1500000],v[1500000],ans1;
void add1(LL a,LL b,LL c)
 {
 	num++;
 	next[num]=head[a];
 	to[num]=b;
 	v[num]=c;
 	head[a]=num;
 
 }
LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
    	if(ch=='-') f=-1;
    	ch=getchar();
    }
    while('0'<=ch&&ch<='9'){
    	x=x*10+ch-'0';
    	ch=getchar();
    }
    return x*f;
}
int main()
{
	freopen("question.in","r",stdin);
	freopen("question.out","w",stdout);
	n=read();
	for(int i=1;i<=n-1;i++)
	 {
	 	x=read();y=read();z=read();
	 	add1(x,y,z);
	 	add1(y,x,z);
	 	dg[x]++;
	 	for(int j=1;j<=3;j++)
	 	 {
	 	 	if(z>fl[x][j])
	 	 	 {
	 	 	 	for(int k=3;k>j;k--)
	 	 	 	 {
	 	 	 	 	fl[x][k]=fl[x][k-1];
	 	 	 	 	ff[x][k]=ff[x][k-1];
	 	 	 	 }
	 	 	 	fl[x][j]=z;ff[x][j]=y;break; 
	 	 	 } 
	 	 }
		dg[y]++;
		for(int j=1;j<=3;j++)
	 	 {
	 	 	if(z>fl[y][j])
	 	 	 {	
	 	 	for(int k=3;k>j;k--)
	 	 	 	 {
	 	 	 	 	fl[y][k]=fl[y][k-1];
	 	 	 	 	ff[y][k]=ff[y][k-1];
	 	 	 	 }
	 	 	 	fl[y][j]=z;ff[y][j]=x;break; 
	 	 	} 	
	 	 }
	 }
	 for(int i=1;i<=n;i++)
	  {
	  	if(dg[i]>=3)
	  	 {
	  	 	LL qwq=dg[i]-1;
	  	 	qwq=(qwq*(qwq-1))/2; 
	  	 	for(int j=head[i];j!=0;j=next[j])
	  	 	 {
	  	 	 	int p=to[j];
	  	 	 	if(dg[p]>=2)
	  	 	 	 {
	  	 	 	  	LL fas;
	  	 	 	  	fas=qwq*(dg[p]-1);
	  	 	 	  	ans+=fas;
	  	 	 	  	sum=0;flagg=0;
	  	 	 	  	for(int k=1;k<=3;k++)
	  	 	 	  	 {
	  	 	 	  	 	if(ff[i][k]!=p)
	  	 	 	  	 	 {
	  	 	 	  	 	   sum+=fl[i][k];
						   flagg++;	
						   if(flagg==2) break;	  	
	  	 	 	  	 	 }
	  	 	 	  	 }
	  	 	 	  	sum+=v[j];
					for(int k=1;k<=3;k++)
					 {
					 	if(ff[p][k]!=i)
					 	 {
					 	 	sum+=fl[p][k];
					 	 	break;
					 	 }
					 }
					ans1=max(sum,ans1); 	   
	  	 	 	 }
	  	 	 }
	  	 }
	  }
	 cout<<ans<<endl;
	 cout<<ans1; 
	 fclose(stdin);fclose(stdout);
	return 0;
}

day2

transact 业务办理

贪心

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0'){
		x=x*10+ch-'0';
	    ch=getchar();
	}
	return x*f;
}
const int N=1e5+7;
struct people{
	LL t,d;
	#define t(x) a[x].t
	#define d(x) a[x].d
}a[N];
LL n,sum=0,mx=0;
bool cmp(const people &x,const people &y){
	return x.d<y.d;
}
int main(){
	freopen("transact.in","r",stdin);
	freopen("transact.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++) t(i)=read();
    for(int i=1;i<=n;i++) d(i)=read();
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
    	sum+=t(i);
    	if(sum>d(i)) mx=max(mx,sum-d(i));
    }
    printf("%lld",mx);
    fclose(stdin);fclose(stdout);
 	return 0;
} 

pass 传球接力

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<ctime>
#define LL long long
#define MOD 1000000007
using namespace std;
int n,i,j,a[500005],d[500005],rd[500005],vis[500005],cyc[500005],len,sum;
int unrd[500005],rt,l,maxn[500005],k;
LL ans;
int main()
{
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d",&a[i],&d[i]);
        rd[a[i]]++;
    }
    for(i=1;i<=n;i++) if(!rd[i]) unrd[++rt]=i;
    while(l<rt){
        k=unrd[++l];
        maxn[a[k]]=max(maxn[a[k]],maxn[k]+d[k]);

        if(--rd[a[k]]==0) unrd[++rt]=a[k]; 
    }
    for(i=1;i<=n;i++)
        if(rd[i]&&!vis[i]){
            k=i;
            len=0;
            sum=0;
			do{
                vis[k]=1;
                cyc[++len]=k;
                sum+=d[k];
                k=a[k];
            }while(k!=i);
            for(j=1;j<=len;j++)  ans=max(ans,(LL)sum-d[cyc[j]]+maxn[a[cyc[j]]]); 
        }
    printf("%lld",ans);
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值