黑龙江大学程序设计竞赛(重现赛)牛客网

A暴力

现在要求上课的同学们把所有的串依次连接起来,于是得到:

那么你能告诉在S串中的第N个字母是多少吗?
1<=N<1e4
解题思路:
懒得找规律。
代码:

#include<bits/stdc++.h>
using namespace std;
inline int read(){
    	int x=0,f=0;char ch=getchar();
    	while(ch>'9'||ch<'0')f|=ch=='-',ch=getchar();
    	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    	return f?-x:x;
}
int main(){
	ios::sync_with_stdio(false);
	string s,p;
	for(int k=0;k<9;++k)for(char i='a';i<='z';++i)s+=i,p+=s;
	int q;cin>>q;
	while(q--){
		int n;cin>>n;
		cout<<p[n-1]<<endl;
	}
	return 0;
}

B思维





解题思路:
拆开找规律
代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline ll read(){
    	ll x=0,f=0;char ch=getchar();
    	while(ch>'9'||ch<'0')f|=ch=='-',ch=getchar();
    	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    	return f?-x:x;
}
const int maxn=5e4+7;
const int mod=1e9+7;
ll a[maxn],sum[maxn];
int main(){
	int t=read();
	while(t--){
		ll n=read(),ans=0,t,p=0;
		for(int i=0;i<n;++i)a[i]=read(),ans+=a[i]*a[i],sum[i+1]=sum[i]+a[i];
		for(int i=0;i<n;++i)p+=a[i]*(sum[n]-sum[i+1]);
		printf("%lld\n",(n-1)*ans-p-p);
	}
	return 0;
}

C数论
爱的魔力转圈圈,想你想到心花怒放黑夜白天,可是我害怕爱情只是一瞬间,转眼会不见,我要慢慢冒险。经过了无数的思想斗争,他要做出这个决定,和喜欢的女孩子表白,但女孩只是留给他一个排列,排列的定义是一个由 1 - n 组成的序列每个数出现并且只出现1次。

现在他需要把1,2,3,…n这n个数通过一定顺序首尾连接形成一个圆环,使得相邻元素互质的对数尽可能多,请输出最大的对数。两个数互质的定义是这两个数的GCD(最大公约数)为1。比如6和4的最大公约数为2,不互质。4和3的最大公约数为1,互质。
解题思路:
n与n+1互质

G博弈

The two new cute boys(Alice and Bob) in the ACM group of HLJU science and technology association have been dreaming of getting these six books written by Mr Jin.
As we all know, there is no such thing as a free lunch. Mr Jin now lets Alice and Bob play a game,and only the winner of the game can get these six books.The rules of the game are as follows.
Suppose(假设) the price of these six books is P, two people take turns in bidding(竞拍), Suppose one party(一方) bid A yuan during the bidding process and the other party(另一方) bid B yuan. Rules require . In this way, the bidding goes on in turn until the price of one party is greater than or equal toP,the party fails and the game ends, Mr Jin awarded these books to another party.
Alice first bid, Bob bid behind him every time, and Alice and Bob use the best strategy(最优策略), who can get these books?

解题思路:
巴什博奕
代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int t;cin>>t;
	while(t--){
		int p,m;cin>>p>>m;
		if((p+m)%(m+1)==0)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	return 0;
}

H模拟
Marzz liked a strange way of memorizing words.
Now these words are placed in an n*m Matrix. He decided to memorize only one line or one column of words every day. She has memorized T days in total, and now she wants to know: for each word, when was the last time she memorized it?


3 3 3
1 2
2 3
1 3

0 0 2
1 1 2
3 3 3
代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
    	int x=0,f=0;char ch=getchar();
    	while(ch>'9'||ch<'0')f|=ch=='-',ch=getchar();
    	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    	return f?-x:x;
}
const int maxn=1e5+7;
int mp[maxn];
int main(){
	int n=read(),m=read(),t=read();
	for(int i=1;i<=t;++i){
		int op=read(),c=read()-1;
		if(op==1)for(int j=0;j<m;++j)mp[c*m+j]=i;
		else for(int j=0;j<n;++j)mp[j*m+c]=i;
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j)printf("%d ",mp[i*m+j]);
		putchar('\n');
	}
	return 0;
}

K贪心思维



2
35
1000000000

17
82
解题思路:
尽量拿⑨
代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline ll read(){
    	ll x=0,f=0;char ch=getchar();
    	while(ch>'9'||ch<'0')f|=ch=='-',ch=getchar();
    	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    	return f?-x:x;
}
const int maxn=5e4+7;
const int mod=1e9+7;
int main(){
	int t=read();
	while(t--){
		ll n=read(),ans=9;
		if(n<10){
			printf("%lld\n",n);
			continue;
		}ll tp=9;
		for(int i=1;;++i){
			if(n<tp*10ll+9){
				ll p=n-tp,pp=0;
				while(p)ans+=p%10,p/=10;
				printf("%lld\n",ans);
				break;
			}
			tp=tp*10+9;
			ans+=9;
		}
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值