2024年西安交通大学程序设计校赛(ABCDEFO)

题目链接:https://vjudge.net/contest/630537#overview

写在前面:今天的训练赛出的题目偏简单,与XCPC的难度差别较大,但是我们这次打的也不是很好,卡在思维题卡了很久也没写出来,还需继续努力······


回归正题

A题

题意

输入a,b,c,d四个数,按题意输出。

思路

签到题,直接输出即可。

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
using namespace std;
const int N=1e6+5;
int a[N];
void solve(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << a+b+2*c+3*d << endl; 
	return ;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

B题

题意

给定起始坐标x,y,在给出它转动的时间和圈数,求这个点转动后和起始坐标点位移。

思路

数学思维,求出起始坐标转动的角度,然后套用数学公式即可

编程

#include<bits/stdc++.h>
//#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
#define PI 3.1415926535
using namespace std;
const int N=1e6+5;
int a[N];
void solve(){
	double x,y,t,v;
	cin >> x >> y >> t >> v;
	double r=sqrt(x*x+y*y);
	double q=t*v-int(t*v);
	q=q*360;
	if(q>180){
		q=360-q;
	}
	q=q*PI/180;
	printf("%.10f",sqrt(2*r*r-2*r*r*cos(q)));
	return ;
}
signed main(){
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

C题

题意

给你两个整数x,y代表纵向坐标,将它转化为平面坐标

思路

套题目给的公式即可

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
#define PI 3.1415926
using namespace std;
const int N=1e6+5;
int a[N];
void solve(){
	double x,y;
	cin >> x >> y;
	double a=x/2+y/2,b=x/2*pow(3,0.5)-y/2*pow(3,0.5);
	printf("%.6f %.6f",a,b);
	return ;
}
signed main(){
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

D题

题意

一共n个人,请找出一条链接图连接这n个数,且影的力量必须大于等于0

思路

考虑最基础的情况:将所有结点构造成一条链,由于支配关系是可传递的,而且只需要保证影的力量非负,构造一条链即可

  • 我们有两种支配的方法
  • 第一种,1 是总支配者,其余每人都支配他后面一个人,也就是每个人支配他后面的所有人。
  • 第二种,n 是总支配者,其余每人都支配他前面一个人,也就是每个人支配他前面的所有人。
  • 对于每次输入的x,y,如果x>=y,我们让sum++,反之sum–,若sum大于等于0,选择方案一,反之选择方案二

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
using namespace std;
const int N=1e5+5;
void solve(){
	int n,m;
	cin >> n >> m;
	int sum=0;
	for(int i=1;i<=m;++i){
		int x,y;
		cin >> x >> y;
		if(x>=y) sum++;
		else sum--;
	}
	if(sum>=0){
		for(int i=1;i<n;++i){
			cout << i+1 << " ";//前面支配后面
		}
		cout << 0;
	}
	else{
		cout << 0 << " ";
		for(int i=2;i<=n;++i){//后面支配前面
			cout << i-1 << " ";
		}
	}
	return ;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

E题

题意

给出n个数的序列ai,要求还原所有楼的大小关系,按照楼层的高低,进行升序排序。

思路

从0进行入手,0是代表当前序列的前面所有序列都比当前序列高,那么我们可以倒着遍历这个序列,当遇到0的时候直接输出该下标,若遍历的数不是0,那么就将该下标存入到ai的序列里面,跟在ai的后面输出即可

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
using namespace std;
const int N=2e5+5;
vector<int> a;
vector<int> b[N];
void solve(){
	int n;cin >> n;
    a.resize(n+1);	
	for(int i=1;i<=n;++i){
		cin >> a[i];
		b[i].push_back(i);//先存入当前下标
	}
	for(int i=n;i>=1;--i){
		if(a[i]==0){//遇到0直接输出b[i]数组里面所有的数
			for(auto j : b[i]){
				cout << j << " ";
			}
		}
		else{
			for(auto j : b[i]){
			b[a[i]].push_back(j);	//将当前下标存入的所有数存入到b[a[i]]里面
			}
		}
	}
	return ;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

F题

题意

给出n个数的序列ai,若ai相同则为同一个骑士团,求每两个骑士团所获得的最大收益

思路

将每个骑士团的值进行相加,然后将两个骑士团相加完后的值相乘即可

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
using namespace std;
const int N=1e6+5;
map<int,int> mp;
void solve(){
	int n,m;	
	cin >> n >> m;
	for(int i=1;i<=n;++i){
		int x;cin >> x;
		mp[x]+=i;
	}
	
	while(m--){
		int a,b;
		int ans=0;
		cin >> a >> b;
		ans+=mp[a]*mp[b];
		cout << ans << endl;
	}	
	return ;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

O题

题意

在这里插入图片描述

思路

找规律,最终找到的规律为n*n,直接输出即可

编程

#include<bits/stdc++.h>
#define int long long 
#define endl "\n"
#define fi first
#define se second
#define PII pair<int,int> 
using namespace std;
const int N=1e6+5;
int a[N];
void solve(){
	int n;cin>>n;
	cout<<n*n;
	return ;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值