SDNU_ACM_ICPC_2020_Winter_Practice_4th [Reproduced]

B - So Easy!

思路:共轭矩阵的构造

C - Reading comprehension HDU - 4990

矩阵快速幂

F - TOYS POJ - 2318

H - Triangle

斐波那契数

#include<bits/stdc++.h>
using namespace std;
int t,a[22]={0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14};
int main(){
	cin>>t;
	for(int i=1;i<=t;i++){
		int x;
		cin>>x;
		printf("Case #%d: %d\n",i,a[x]);
	}
	return 0;
}

I - Birthday Paradox

这道题是一个概率论的问题,比赛时以为与二项式有关,又没做出来
假如一年有n天,第一个人可以选择任何一天,所以概率是一。第二个人是(n-1)/n,…,相乘是不相等的概率,再用1减就是有相等的概率

#include<bits/stdc++.h>
using namespace std;
int n,m,sum;double x,y;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&m);
		x=1,y=m-1,sum=0;
		while(x>0.5){
			x*=y/m;
			y--;
			sum++;
		}
		printf("Case %d: %d\n",i,sum);
	}
	return 0;
}

J - Magic Square

模拟
我第一次写麻烦了,要充分利用函数呀.
最后要注意输入

#include<bits/stdc++.h>
using namespace std;
int s[4][4];
int t,n;
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			char s1;
			cin>>s1;
			s[i][j]=s1-'0';
		}
		while(n--){
			string opt;
			cin>>opt;
			if(opt[1]=='C'){
				if(opt[0]=='1'){
					int y=s[2][2];s[2][2]=s[1][2];s[1][2]=s[1][1];s[1][1]=s[2][1];s[2][1]=y;
				}
				else if(opt[0]=='2'){
					int y=s[2][3];s[2][3]=s[1][3];s[1][3]=s[1][2];s[1][2]=s[2][2];s[2][2]=y;
				}
				else if(opt[0]=='3'){
					int y=s[3][2];s[3][2]=s[2][2];s[2][2]=s[2][1];s[2][1]=s[3][1];s[3][1]=y;					
				}
				else{
					int y=s[3][3];s[3][3]=s[2][3];s[2][3]=s[2][2];s[2][2]=s[3][2];s[3][2]=y;					
				}
			}
			else{
				if(opt[0]=='1'){
					int y=s[2][2];s[2][2]=s[2][1];s[2][1]=s[1][1];s[1][1]=s[1][2];s[1][2]=y;
				}
				else if(opt[0]=='2'){
					int y=s[2][3];s[2][3]=s[2][2];s[2][2]=s[1][2];s[1][2]=s[1][3];s[1][3]=y;
				}
				else if(opt[0]=='3'){
					int y=s[3][2];s[3][2]=s[3][1];s[3][1]=s[2][1];s[2][1]=s[2][2];s[2][2]=y;					
				}
				else{
					int y=s[3][3];s[3][3]=s[3][2];s[3][2]=s[2][2];s[2][2]=s[2][3];s[2][3]=y;					
				}
			}			
			}
			for(int i=1;i<=3;i++)
			for(int j=1;j<=3;j++)
			if(j==3)
			cout<<s[i][j]<<endl;
			else
			cout<<s[i][j];	
		}
	}
#include<bits/stdc++.h>
using namespace std;
int s[4][4];
char s1;
int t,n;
void solve(int &a,int &b,int &c,int &d,char e){
	if(e=='C'){
		int y=a;
		a=c;c=d;d=b;b=y;
	}
	else{
		int y=d;d=c;c=a;a=b;b=y;
	}
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			cin>>s1;
			s[i][j]=s1-'0';
		}
		while(n--){
			string opt;
			cin>>opt;
			if(opt[1]=='C'){
				if(opt[0]=='1')solve(s[1][1],s[1][2],s[2][1],s[2][2],'C');
				else if(opt[0]=='2')solve(s[1][2],s[1][3],s[2][2],s[2][3],'C');
				else if(opt[0]=='3')solve(s[2][1],s[2][2],s[3][1],s[3][2],'C');
				else solve(s[2][2],s[2][3],s[3][2],s[3][3],'C');
			}
			else{
				if(opt[0]=='1')solve(s[1][1],s[1][2],s[2][1],s[2][2],'R');
				else if(opt[0]=='2')solve(s[1][2],s[1][3],s[2][2],s[2][3],'R');
				else if(opt[0]=='3')solve(s[2][1],s[2][2],s[3][1],s[3][2],'R');
				else solve(s[2][2],s[2][3],s[3][2],s[3][3],'R');				
			}
		}
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++)
			cout<<s[i][j];
			cout<<endl;
		}
	}
	return 0;
}

K - Reverse a Substring

字符串不能是递减的

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n;
bool ok;
char s[maxn];
int main(){
	cin>>n;
	int x,y;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		if(i!=1&&s[i]<s[i-1]){
			x=i-1;
			y=i;
			ok=true;
		}
	}
	if(ok){
		cout<<"YES"<<endl<<x<<" "<<y<<endl;
	}
	else
	cout<<"NO"<<endl;
	return 0;
}

L - Game with Telephone Numbers

这道题思路是对的,比赛时没做出来(比赛时一定要冷静保持清醒的头脑啊),现在冷静下来了,一遍过了

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int s[maxn];
int n;
char c;
bool ok;
int main(){
	cin>>n;
	int sum=(n-11)/2,sum_=0;
	for(int i=1;i<=n;i++){
		cin>>c;
		s[i]=c-'0';
		if(s[i]==8)
		sum_++;
		if(sum_==sum+1&&(i>=sum+1&&i<=sum*2+1)){
			ok=true;
		}
	}
	if(ok)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

M - Alarm Clocks Everywhere

求多个最大公约数,可以类似于嵌套多个函数,max(max(a,b),c),所以可以
gcd(gcd(a,b),c).
0和a的最大公约数为a
本题:a[i]+cd=a[i+1],要找出这些cd所有的公约数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+10;
int n,m,sum;
ll s,x,y,a[maxn];
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
	scanf("%lld",&a[i]);
	    if(i!=1)
		y=gcd(a[i]-a[i-1],y);
	}
	for(int i=1;i<=m;i++){
		scanf("%lld",&s);
		if(y%s==0){
			sum=i;
		}
	}
	if(sum==0){
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
		printf("%lld %d\n",a[1],sum);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值