第四届ACM-ICPC“青春杯“程序设计竞赛题解

B-三等分角

Description 尺规作图三等分角是古希腊三大几何问题之一…
现在将这个问题稍作简化,给定三角形ABC,需要你在线段BC上找一点D使得: ( ∠BAC = 3 * ∠BAD )

Input
六个浮点数分别是x1,y1,x2,y2,x3,y3,分别代表点A(x1,y1),B(x2,y2), C(x3,y3)的坐标。

Output
输出点D的坐标,结果保留两位小数。

Sample Input
0 0 0 1 1 1

Sample Output
0.27 1.00

HINT
0<= x, y <=1e8

在这里插入图片描述
这题用二分可以少考虑很多东西(注意不要把三等分角和三等分点混淆)
版本1:暴力求解

#include <bits/stdc++.h>
using namespace std;
double PI=acos(-1);

long double aw(long double x1,long double y1,long double x2,long double y2) {
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

long double cv(long double a,long double b,long double c) {
    return acos((b*b+c*c-a*a)/(2*b*c));
}

int main()
{
    long double x1,y1,x2,y2,x3,y3;
    scanf("%Lf%Lf%Lf%Lf%Lf%Lf",&x1,&y1,&x2,&y2,&x3,&y3);
    
    long double a=aw(x2,y2,x3,y3);
	long double b=aw(x1,y1,x3,y3);
	long double c=aw(x1,y1,x2,y2);
    long double Q=cv(a,b,c);
    long double s1=x2,yy1=y2,s2=x3,yy2=y3;
    
    while(fabs(s1-s2)>1e-5)
    {
        long double x,y;
        x=(s1+s2)/2,y=(yy1+yy2)/2;
        
        long double c1=aw(x1,y1,x2,y2);
		long double a1=aw(x2,y2,x,y);
		long double b1=aw(x1,y1,x,y);
        long double Q1=cv(a1,b1,c1);
        
        if(Q1>=Q/3) s2=x,yy2=y;
        else s1=x,yy1=y;
    }
    printf("%.2Lf %.2Lf",s1,yy1);
    return 0;
}

版本2:二分

#include <iostream>
#include <cmath>
#define eps 1e-5 //eps是二分精度,如果有问题就把他调得再小一些
using namespace std;
double x[4],y[4];

double lenth(double x1,double y1,double x2,double y2) {
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

inline double BAD(double ans_x,double ans_y) {
	double a=lenth(x[1],y[1],x[2],y[2]);
	double b=lenth(x[1],y[1],ans_x,ans_y);
	double c=lenth(x[2],y[2],ans_x,ans_y);
	return acos((a*a+b*b-c*c)/a/b/2.0);
}

int main() 
{
	for(int i=1; i<=3; i++)  cin>>x[i]>>y[i];
	double ans_x,ans_y,lx=x[2],rx=x[3],ly=y[2],ry=y[3];
	double BAC = BAD(x[3],y[3]);
	while(abs(rx-lx)>eps) {
		ans_x=(lx+rx)/2; 
		ans_y=(ly+ry)/2;
		if(BAD(ans_x,ans_y)*3>=BAC)  rx=ans_x,ry=ans_y;
		else lx=ans_x,ly=ans_y;
	}
	printf("%.2lf %.2lf\n",ans_x,ans_y);
	return 0;
}

C-单科成绩排序

Description
n个学生,每人m门成绩,现在要求根据第i门成绩由高到低排序。

Input
第一行两个整数,分别是:n,m;
接下来n行,每行m个数,表示第i个人的第j门分数;
第n+2行,一个整数k,表示有k组询问;
接下来k行,每行一个整数t (1<=t<=m),表示根据第t门成绩排序.

Output
根据第i门成绩排序后的n个人的名次.如果此门科目存在多个人的成绩相同,由序号从小到大输出。

Sample Input
4 3 95 53 68 41 70 65 33 53 91 66 41 99 2 2
3 Sample Output
2 1 3 4 4 3 1 2

HINT
1<=n<=10000;
1<=t<=m<=100;
1<=k<=100;
0<=分数<=100;

注意大数快读,自定义排序函数

#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+10,M=2e5;
typedef long long LL;

inline int read() {
    int x=0,f=1;
    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;
}
inline string readstring() {
    string str;
    char s=getchar();
    while(s==' '||s=='\n'||s=='\r') {
    	s=getchar();
    }
    while(s!=' '&&s!='\n'&&s!='\r') {
    	str += s;
    	s=getchar();
    }
    return str;
}

struct f{int a[110],z,nu;}s[N];

bool cmp(struct f x,struct f y) {
	if(x.z==y.z) return x.nu<y.nu;
	return x.z>y.z;
}

int main()
{
	int n,m;
	n=read(),m=read();
	for(int i=1; i<=n; i++)
	    for(int j=1; j<=m; j++)
	    {
	 	    scanf("%d",&s[i].a[j]);
	 	    s[i].nu=i;
	    }
	int k;	k=read();
	while(k--)
	{
		int p;
		p=read();
		for(int i=1; i<=n; i++)	 
			s[i].z=s[i].a[p];
		sort(s+1,s+n+1,cmp);
		for(int i=1; i<=n; i++)	 
			printf("%d ",s[i].nu);
		printf("\n");
	}
	return 0;
}

D-任意进制A+B

在这里插入图片描述

Sample Input
170 169 2 2 1 0 2 1 1

Sample Output
1 0 1 0 1 0 1 0 0

HINT
((0){10} <= (a)x , (b)y <= (10^{17}){10} ) ((2){10} <= x , y , z <= (10^{17}){10} )

C++版

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=1e5+10;
ll x,y,z,a[N],b[N],s[N],Q1,Q2;
int la,lb;

int main()
{
	scanf("%lld %lld %lld %d",&x,&y,&z,&la);
    for(int i=la-1; i>=0; i--)  cin>>a[i];
    scanf("%d",&lb);
    
    for(int i=lb-1; i>=0; i--)  cin>>b[i];
    for(int i=0; i<=la-1; i++)  Q1 += a[i]*pow(x,i);
    for(int i=0; i<=lb-1; i++)  Q2 += b[i]*pow(y,i);
    
    ll Q=Q1+Q2;  int S=0;
    
    while(Q) {
        int t = Q%z;
        s[++S] = t;
        Q /= z;
    }
    
    for(int i=S; i>=1; i--)  cout<<s[i]<<" ";
    return 0;
}

JAVA版:直接把他们化成二进制,再变成c的进制

import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			long a,b,c;
			a=sc.nextLong();b=sc.nextLong();c=sc.nextLong();
				int l1=sc.nextInt();
				int x[]=new int[l1];
					for (int i = 0; i < x.length; i++) {
						x[i]=sc.nextInt();
					}
				int l2=sc.nextInt();
				int y[]=new int[l2];
					for (int i = 0; i < y.length; i++) {
						y[i]=sc.nextInt();
					}
				long result1,result2;
				result1=result2=0;
				System.out.println(Arrays.toString(x));
				System.out.println( Arrays.toString(y));
				//
				for (int i = 0; i < x.length; i++) {
					result1+=x[i]*Math.pow(a, l1-1-i);
				}
				for (int i = 0; i < y.length; i++) {
		
					result2+=y[i]*Math.pow(b, l2-1-i);
				}
				long ok=result1+result2;
			
				System.out.println(Long.toString(ok,(int) c));
		
		}
	}
}

I-博弈论

Description:
给定两个正整数 M 和 N,从 Stan 开始,从其中较大的一个数,减去较小的数的正整数倍,当然,得到的数不能小于 0。然后是 Ollie,对刚才得到的数,和 M,N 中较小的那个数,再进行同样的操作……直到一个人得到了 0,他就取得了胜利。下面是他们用 (25,7) 两个数游戏的过程:

Start:(25,7)(25,7)
Stan:(11,7)(11,7)
Ollie:(4,7)(4,7)
Stan:(4,3)(4,3)
Ollie:(1,3)(1,3)
Stan:(1,0)(1,0)
Stan 赢得了游戏的胜利。
现在,假设他们完美地操作,谁会取得胜利呢?

Input
每行两个正整数 M,N(M,N<2^{31})。
Output
输出一行,如果 Stan
胜利,则输出 Stan wins;否则输出 Ollie wins。

Sample Input
24 15
Sample Output
Ollie wins

套板子,找规律

#include <bits/stdc++.h>
#define ll long long  
using namespace std;
int a[2021]={0};

int  main()
{
	int a,b,temp,ans=0;
	cin>>a>>b;
	if(a<b) swap(a,b);
	while(b!=0)
	{
		if(a>2*b || a%b==0)   break;
		a -= b;
		swap(a,b);
		ans ^= 1;
	}
	if(ans)  cout<<"Ollie wins"<<endl;
	else  cout<<"Stan wins"<<endl;
	return 0;
}

L-最短路

Description
给定一个 n×m 的棋盘,上面有两种格子#和@。游戏的规则很简单:给定一个起始位置和一个目标位置,小明每一步能向上,下,左,右四个方向移动一格。如果移动到同一类型的格子,则费用是0,否则费用是1。计算从起始位置移动到目标位置的最小花费。

Input
多组数据
输入第一行包含两个整数n,m,分别表示棋盘的行数和列数,当n = 0 且 m = 0时结束。 输入接下来的n 行,每一行有 m 个格子(使用#或者@表示)。 输入接下来一行有四个整数(x_1, y_1, x_2, y_3)分别为起始位置和目标位置。
Output
输出从起始位置到目标位置的最小花费。

Sample Input
2 2
@#
#@
0 0 1 1
2 2
@@
@#
0 1 1 0 0 0
Sample Output
2 0

HINT
对于20%的数据满足:1≤n,m≤10。
对于40%的数据满足:1≤n,m≤300。
对于100%的数据满足:1≤n,m≤500。

用DFS好像会被卡…

#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define ll long long  
using namespace std;
const int N=501000,M=666;
const int dx[4]={0,-1,0,1}, dy[4]={-1,0,1,0};
struct node{int x,y;}lt[N];
int hy,ty,d[M][M],n,m,vx,vy,px,py;
char mp[M][M];
bool v[M][M];

int wm(int x,int y,int u,int v)
{
    if(mp[x][y]!=mp[u][v])
	    return 1;
    return 0;
}

int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)  break;
        for(int i=1; i<=n; i++)  scanf("%s",mp[i]+1);
        scanf("%d %d %d %d",&vx,&vy,&px,&py);
        vx++; vy++; px++; py++;
        memset(d,63,sizeof(d));
        d[vx][vy]=0;
        memset(v,false,sizeof(v));
        lt[1].x=vx;	   lt[1].y=vy;
		v[vx][vy]=true;
        hy=1;	ty=2;
        while(hy!=ty)
        {
            node t=lt[hy];
            for(int k=0; k<=3; k++)
            {
                int x=t.x+dx[k],y=t.y+dy[k];
                if(x<1||x>n||y<1||y>m)  continue;
                int op=wm(t.x,t.y,x,y);
                if(d[x][y]>d[t.x][t.y]+op)
                {
                    d[x][y]=d[t.x][t.y]+op;
                    if(v[x][y]==false)
                    {
                        v[x][y]=true;
                        lt[ty].x=x;	 lt[ty].y=y;
                        ty++;
						if(ty==n*m+1)  ty=1;
                    }
                }
            }
            v[t.x][t.y]=false;    hy++;
			if(hy==n*m+1)  hy=1;
        }
        printf("%d\n",d[px][py]);
    }
    return 0;
}
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ACM-ICPC(国际大学生程序设计竞赛)是一项全球性的大学生程序设计比赛,每年吸引来自世界各地的顶尖大学代表队参与。ACM-ICPC竞赛的核心内容是团队编程和问题决能力。 首先,ACM-ICPC竞赛对参赛选手的编程能力要求很高。参赛队伍需要在规定的时间内决一系列的算法问题,这些问题常常包含复杂的数据结构和算法,要求选手在有限的时间内设计和实现高效的程序。 其次,ACM-ICPC竞赛强调团队协作。每个队伍由三名选手组成,他们需要分工合作,保持良好的沟通与协调,共同决问题。团队成员需要相互理、相互信任,快速地协商和决策,同时要保持高效的任务分配和时间管理。 此外,ACM-ICPC竞赛也需要选手具备良好的问题决能力。这些问题往往是实际应用或理论推导相关的,选手需要从数学、计算机科学和算法等多个角度出发,找到最佳决方案。在面对问题时,选手需要对问题进行分析、抽象和建模,运用各种算法和数据结构进行决。 对于参赛选手来说,ACM-ICPC提供了一个学习与交流的平台。在比赛中,选手可以接触到不同国家和地区的优秀程序设计人才,学习他们的思维方式和编程技巧。同时,ACM-ICPC还举办了一系列的培训和研讨会,让选手有机会深入了计算机科学和算法领域最新的研究成果。 总之,ACM-ICPC国际大学生程序设计竞赛是一个挑战性与学习性兼具的比赛。它要求选手具备扎实的编程技能、团队合作能力和问题决能力。参与此竞赛不仅可以锻炼自己的编程能力,还能与全球的顶尖程序设计人才进行交流,拓宽自己的视野和思维方式。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米莱虾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值