上学赛题解

比赛链接

前言:

Z H K ZHK 才不向 G Y X GYX 一样连题解都懒得写,于是 Z H K ZHK 写了。。。

T 1 T1 W A T E R WATER

先看题意,就是看那些格子不能放 S J B SJB ,然后根据排列组合公式,最一个 2 n 2^{n} 的高精就行了,为什么要高精,因为最大值甚至可能是 2 30 30 2^{30*30} 也就是 2 900 2^{900}

S o So

L e t s Let's l o o k look a t at t h e the c o d e : code:

#include <bits/stdc++.h>
using namespace std;
int x[24000],y[24000];
string tostring(int a){
	if(a==0)return "0";
	string st="";
	while(a){
		st=char(a%10+48)+st;
		a/=10;
	}return st;
}
string jf(string a,int b){
    int c=-1,l1;
    string z="";
    for(int i=a.size()-1;i>=0;i--){
        c++;
        x[c]=a[i]-48;
    }l1=a.size();
    for(int i=0;i<l1;i++)y[i]=x[i]*b;
    for(int i=0;i<l1-1;i++){
        y[i+1]=y[i+1]+y[i]/10;
        y[i]=y[i]%10;
    }
    for(int i=l1-1;i>=0;i--)z=z+tostring(y[i]);
    return z;
}
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,1,-1,1,-1};
int f[35][35];
int main(){
    int n;
    cin>>n;
	int a,b,x,y,s=0;
	cin>>a>>b>>x>>y;
	f[x][y]=1;
	for(int i=0;i<8;i++){
		int tx=x+dx[i],ty=y+dy[i];
		if(tx>=1&&tx<=n&&ty>=1&&ty<=n)f[tx][ty]=1;
	}
	if(f[a][b]==1){
		cout<<0;
		return 0;
	}
	for(int i=0;i<8;i++){
		int a1=a,b1=b;
		while(a1>=1&&a1<=n&&b1>=1&&b1<=n){
			f[a1][b1]=1;
			a1+=dx[i];
			b1+=dy[i];
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(!f[i][j])s++;
	if(s==0){
		cout<<0;
		return 0;
	}
	string st="1";
	for(int i=1;i<=s;i++)st=jf(st,2);
	cout<<st;
	return 0;
}

S o So e a s y ! easy! I s n t Isn't i t ? it?

T 2 T2 e m em

貌似大家都懒得想,直接输样例那 50 50 分了吧!样例分给的确实有点高。。。

这道题数据小得真的可怜。。。

正解:暴搜!!!

注意细节啦,其余的也没啥的吧。

S o So

L e t s Let's l o o k look a t at t h e the c o d e : code:

#include <bits/stdc++.h>
using namespace std;
template<class T>inline void read(T &x){
	x=0;T f=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-f;
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	x*=f;
}//王星钱的快读,我直接借他的抄了,不知道他会不会同意。。。
int a[260][260],b[260][260],f[260];
queue<int>x;
queue<int>y;
int main(){
	int n,m,t;
	read(n),read(m);read(t);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			read(a[i][j]),read(b[i][j]);
	x.push(m);
	y.push(t);
	while(x.size()){
		for(int i=1;i<=n;i++){
			if(f[x.front()]+b[x.front()][i]>f[i]&&y.front()>=a[x.front()][i]){
				f[i]=f[x.front()]+b[x.front()][i];
				x.push(i);
				y.push(y.front()-a[x.front()][i]);
			}
		}x.pop();
		y.pop();
	}cout<<f[m];
	return 0;
}

貌似 w x q 1229 wxq1229 大佬说可以最短路, e m em ,貌似不可以。

T 3 T3 原题

貌似大家都去输样例得 10 10 分了。。。

其实,这道题是有原题的。那么,是哪一道呢? L e t Let m e me t e l l tell y o u you

此处已对数据加强。

此处对数据加强。

S o So

L e t s Let's l o o k look a t at t h e the c o d e : code:

#include <bits/stdc++.h>
using namespace std;
long long dp[5010][5010][2],s[5010],a[5010];
int main(){
	int n,c;
	cin>>n>>c;
	memset(dp,0x3f,sizeof(dp));
	for(int i=1;i<=n;i++){
		cin>>a[i]>>s[i];
		s[i]+=s[i-1];
	}
	dp[c][c][0]=0;
	dp[c][c][1]=0;
	for(int j=c;j<=n;j++)
		for(int i=j-1;i>=1;i--){
			dp[i][j][0]=min(dp[i+1][j][0]+(a[i+1]-a[i])*(s[i]+s[n]-s[j]),dp[i+1][j][1]+(a[j]-a[i])*(s[i]+s[n]-s[j]));
            dp[i][j][1]=min(dp[i][j-1][0]+(a[j]-a[i])*(s[i-1]+s[n]-s[j-1]),dp[i][j-1][1]+(a[j]-a[j-1])*(s[i-1]+s[n]-s[j-1]));
		}
	cout<<min(dp[1][n][1],dp[1][n][0]);
	return 0;
}

T 4 T4 数据出水了。。。

本想卡 O ( T m a x ( a , b ) ) O(T\sqrt{max(a,b)})

然而,我没有成功。

现在,大家了解一下标程的复杂度 O ( T log 2 m a x ( a , b ) ) O(T\log2{max(a,b)}) ,也就相当于 gcd \gcd 复杂度!

S o So

L e t s Let's l o o k look a t at t h e the c o d e : code:

#include <bits/stdc++.h>
using namespace std;
inline int read(){
    register int s=0,f=1;
    register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}
    while(isdigit(ch))s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
    return s*f;
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}
int gcd(int a,int b){
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int f[1000010],h[600010],len;
int work(int x){
	int tot=0,y=1,z=x;
	pair<int,int>a[110];
	while(x>=h[y]){
		int s=0;
		while(x%h[y]==0)x/=h[y],s++;
		if(s)a[++tot]=make_pair(h[y],s);
		y++;
	}//for(int i=1;i<=tot;i++)cout<<i<<" "<<a[i].first<<" "<<a[i].second<<endl;
	if(tot==1)return z/a[1].first/a[1].first;
	else if(a[1].second==1)return z/a[2].first;
		else return z/min(a[1].first*a[1].first,a[2].first);
}
int main(){
	for(int i=2;i<=100000;i++)
		if(!f[i]){
			h[++len]=i;
			for(int j=i*2;j<=100000;j+=i)f[i]=1;
		}
	int T=read();
	while(T--){
		int a=read(),b=read(),x=gcd(a,b),y=1,s=0;
		if(f[x]==0)puts("0");
		else{
			write(work(x));puts("");
		}
	}
	return 0;
}

最后再说一句,本来我还想卡非快读的程序。。。

貌似 @zmxqs O ( T m a x ( a , b ) ) O(T\sqrt{max(a,b)}) 的程序靠 O 2 O2 碾压标程

T 5 T5 是从一道原题改编的

原题

在此,不细讲,请
不要忘记点赞哦!

T 6 T6 送分

同样是一道原题,各个 O J OJ 上基本都有

这里给出洛谷网址

最后贴出主程序一行的程序

#include <bits/stdc++.h>
using namespace std;
inline int read(){
    register int s=0,f=1;
    register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}
    while(isdigit(ch))s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
    return s*f;
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}
int main(){
	wrtie(read()+read());
}//我才不写return 0呢

后记

本次比赛, y q m 2007 yqm2007 多得了第 1 1 ,恭喜他,这是他第 1 1 次获奖,可谓是小试牛刀,他将获得有 s k i y g y x skiy_gyx 提供的10 R M B RMB

本次比赛共 46 46 人得分, 64 64 人报名,多人 A C AC 了我认为有难度的 T 4 T4 y q m 2007 yqm2007 A C AC T 1 T1

本次比赛圆满结束!

发布了56 篇原创文章 · 获赞 86 · 访问量 1880

猜你喜欢

转载自blog.csdn.net/qq_46230164/article/details/105353323