湖南大学第十六届程序设计竞赛

湖南大学第十六届程序设计竞赛

蒟蒻第一次写,只写了部分题目(在爬了)

A-Triangles

给出三个点的坐标,判断三个点构成的三角形是直角三角形还是钝角三角形还是锐角三角形或者不能构成三角形。

其中不能构成三角形的情况就是三个点共线即斜率相等。当三角形两个边的平方和大于最长边的平方和时为锐角三角形,等于时为直角三角形,小于时为钝角三角形。

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	while(n--){
		double x1,x2,x3,y1,y2,y3,l1,l2,l3;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		//三边平方
		l1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		l2=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);
		l3=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
		//求斜率
		double k1=(y1-y2)/(x1-x2);
		double k2=(y2-y3)/(x2-x3);
		double k3=(y3-y1)/(x3-x1);
		if(k1==k2||k2==k3||k1==k3){
			cout<<"invalid"<<endl;continue;
		}
		else if(x1==x2&&x2==x3&&x1==x3){
			cout<<"invalid"<<endl;continue;
		}
		if(l1+l2>l3&&l3+l2>l1&&l1+l3>l2)
			cout<<"acute"<<endl;
		else if(l1+l2==l3||l3+l2==l1||l1+l3==l2)
            cout<<"right"<<endl;
        else
            cout<<"obtuse"<<endl;
	}
	return 0;
}

D-Queuing

一个队列中的所有人冲向n个窗口组成n个新队列,求第m个人在新队列的排名期望。

第m个人前面有m-1个人,每个人冲向与m相同的新窗口的概率为1/n,再加上m自己的概率1

#include<bits/stdc++.h>
using namespace std;
int main(){
	double n,m;
	cin>>n>>m;
	printf("%.8lf",1+(m-1)/n);
	return 0;
}

 F-Team

大数相加

#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[20],b[20],c[20];
	int d[30]={0};
	int l1,l2,l3;
	cin>>a>>b>>c;
	l1=strlen(a);
	l2=strlen(b);
	l3=strlen(c);
	int maxx=max(l1,max(l2,l3));
	int t=0,cnt=0;
	while(maxx>0){
		if(l1>0){
			t=t+a[l1-1]-'0';
			l1--;
		}
		if(l2>0){
			t=t+b[l2-1]-'0';
			l2--;
		}
		if(l3>0){
			t=t+c[l3-1]-'0';
			l3--;
		}
		if(t>=10){
			d[cnt++]=t%10;
			t/=10;
		}
		else{
			d[cnt++]=t;
			t=0;
		}
		maxx--;
	}if(t!=0)d[cnt++]=t;
	for(int i=cnt-1;i>=0;i--){
		cout<<d[i];
	}return 0;
} 

 G-Binbin's string

s字符串经过多少次特定的改变可以变成t字符串。

有三种情况,当s和t字符串一样时,则不需要改变,输出0

当s只增加或删除一个地方就可以跟t一样时,输出1

当s与t有很多不一样的地方时只需要把s都删去在把t替换上,则输出2

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    if(s==t){
        cout<<'0'<<endl;
    }
    else{
    	int cnt=0;
    	while(s[cnt]==t[cnt])cnt++;
   		int l1=s.length()-1,l2=t.length()-1;
   		while(s[l1]==t[l2]){
        	l1--;l2--;
   		}
    	if(l1<=cnt||l2<=cnt) cout<<'1'<<endl;
    	else cout<<'2'<<endl;
	}
    return 0;
}

L-Cracked Pipes

建图之后dfs,要注意能与(1,0)和(n,m+1)。a b两点相连的只有2,5,6。两个点可以相连的标准是a的管道可以到b,b的管道可以到a

#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<int,map<int,int> >mp,a;
bool t[10][5],A;
int n,m;
int dx[5]={-1,0,1,0};
int dy[5]={0,1,0,-1};
void dfs(int x,int y,int f){
    if(x==n&&y==m+1){
        if(t[2][f])A=1;
    }
    if(x>n||y>m||x<1||y<1||a[x][y])return;
    int xx=mp[x][y];
    if(t[xx][f]){
        a[x][y]=1;
        for(int i=0;i<4;i++){
            if(t[xx][i])dfs(x+dx[i],y+dy[i],(i+2)%4);
        }
    }
    else return;
}
int main(){
    t[1][0]=t[1][2]=t[2][1]=t[2][3]=t[3][1]=t[3][2]=t[4][0]=1;
    t[4][3]=t[5][0]=t[5][1]=t[5][3]=t[6][1]=t[6][2]=t[6][3]=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>mp[i][j];
        }
    }
    dfs(1,1,3);
    if(A)cout<<"YES";
    else cout<<"NO";
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值