【noip2018模拟赛0】解题报告

清新不毒瘤的模拟赛

阅读全文大概需要 10分钟
本文总阅读量
Posted by yjjr's blog on October 21, 2018

T1 yyy点餐

题意

给出长度为\(n\)的序列,求有所有不同的组合的代价总和(每种组合的代价为该组合内所有数之和)

对于全部数据,有\(1\leq n\leq 1000000, 0\leq a_i<998244353\)

题解

一眼就能秒掉的水题

\[ans=\sum_{i=1}^n C(n,i) \times \sum_{i=1}^n a[i]\]

求组合数的话,就用乘法逆元即可

code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define ll long long
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//******head by yjjr******
const ll mod=998244353;
int n;
ll sum1=1,sum2=0;
ll inv(ll a){return a==1?1:(ll)(mod-mod/a)*inv(mod%a)%mod;}
void C(ll n,ll m){
	if(m<0||n<m)return;//if(m>n-m)m=n-m;
	ll up=1,down=1;
	rep(i,0,m-1){up=up*(n-i)%mod;down=down*(i+1)%mod;sum1+=up*inv(down)%mod;sum1%=mod;}
}
int main(){
	freopen("T1.in","r",stdin);
	freopen("T1.out","w",stdout);
	n=read();
	C(n-1,n-1);//puts("R");
	rep(i,1,n)sum2+=read(),sum2%=mod;
	//cout<<sum1<<' '<<sum2<<endl;
	cout<<1ll*sum1*sum2%mod<<endl;
	return 0;
} 

T2 yyy送礼物

题意

求\(\sum_{i=1}^n n\%i\)

对于全部数据,有\(0\leq T\leq 1000000,1\leq n\leq 10000000\)

题解

毒瘤数论题

先是找规律手玩了2h,最后对拍发现规律找错了GG

然后推式子

\[ans=\sum_{i=1}^n n\%i = \sum_{i=1}^n n-\lfloor \frac n i\times i\rfloor\] \[= \sum_{i=1}^n n- \sum_{i=1}^n\lfloor \frac n i\rfloor \times i =n^2- \sum_{i=1}^n\lfloor \frac n i\rfloor \times i\]

然后可以用线性筛求约数和

安利一下这篇博文非常适合学习线性筛

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//**********head by yjjr**********
const int maxn=1e7+6;
bool not_prime[maxn+6];
int prime[maxn],cnt=0;
ll sd[maxn+6],sp[maxn+6],pre[maxn+6];
void Pre(){
	not_prime[1]=1;sd[1]=sp[1]=1;
	rep(i,2,maxn){
		if(!not_prime[i]){
			prime[++cnt]=i;
			sd[i]=sp[i]=i+1;
		}
		rep(j,1,cnt){
			if(i*prime[j]>maxn)break;
			not_prime[i*prime[j]]=1;
			if(i%prime[j]==0){
				sd[i*prime[j]]=sd[i]/sp[i]*(sp[i]*prime[j]+1);
				sp[i*prime[j]]=sp[i]*prime[j]+1;
				break;
			}else{
				sd[i*prime[j]]=sd[i]*sd[prime[j]];
				sp[i*prime[j]]=prime[j]+1;
			}
		}
	}
	rep(i,1,maxn)pre[i]=pre[i-1]+sd[i];
}

int main()
{
	freopen("T2.in","r",stdin);
	freopen("T2.out","w",stdout);
	Pre();
	int T=read();
	while(T--){
		ll x=read();
		printf("%lld\n",x*x-pre[x]);
	}
	return 0;
}

T3 yyy的迷失

题意

给出大小为\(m\times m\)的正方形,其中有一些带方向的箭头(平行于x轴或y轴),从一个点出发(给定方向),如果遇到箭头,就会沿着箭头走,问最后停留在什么位置

对于全部数据,保证:\(1\leq n,m,q\leq 10^5, 0\leq x1,y2,x2,y2,x2,y2\leq m,0\leq T\leq 10^{15}\)

(伪)题解

一看就是数据结构题,再看下std的代码长度,\(\geq 11k\),开始弃疗

然后放上50pts的暴力代码

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//**********head by yjjr**********
const int maxn=3e3+6;
int Map[maxn][maxn]={0},x1,x2,y1,y2,k,n,m,T;
char ch;
void check(){
	if(x1==x2){
		if(y1<y2)rep(i,y1,y2)Map[x1][i]=1;
		else rep(i,y2,y1)Map[x1][i]=2;
	}
	else if(y1==y2){
		if(x1>x2)rep(i,x2,x1)Map[i][y1]=3;
		else rep(i,x1,x2)Map[i][y1]=4;
	}
}
int main()
{
	freopen("T3.in","r",stdin);
	freopen("T3.out","w",stdout);
	n=read(),m=read();
	rep(i,1,n){
		x1=read(),y1=read(),x2=read(),y2=read();
		check();
	}
	T=read();
	while(T--){
		int x=read(),y=read();
		cin>>ch;getchar();int t=read();
		if(ch=='U')k=1;
        if(ch=='D')k=2;
        if(ch=='L')k=3;
        if(ch=='R')k=4;
	//	cout<<k<<"R\n";
		rep(j,1,t){
			if(Map[x][y]!=0)k=Map[x][y];
            if(k==1)y++;
            if(k==2)y--;
            if(k==3)x--;
            if(k==4)x++;
			if(x>m){x--;break;}
			else if(x<0){x++;break;}
			else if(y>m){y--;break;}
			else if(y<0){y++;break;}
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}
本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr