2020全国高校计算机能力挑战赛C++决赛代码分享

科技节编程大赛一等奖作品——朱瑞超 姓名:朱瑞超 用时:1小时10分钟 第一题: 源代码: #include main() {          intx,y,m,n,l;          intcount=0;          printf("请输入x的值\n");          scanf("%d",&x);          printf("请输入y的值\n"); 阅读详情

样例均过(2020.1.3更新:一等奖)

1.模拟

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {
	int n;
	cin >> n;
	double hun, su, zhushi, tang;
	cin >> hun >> su >> zhushi >> tang;
	double hot = 0, zhushiweight = 200, cost = 0;
	bool flag = 0;
	for (int i = 0; i < n; ++i) {
		char sign;
		double weight, perhot;
		cin >> sign >> weight >> perhot;
		if (sign == 'M') {
			cost += hun * weight / 100;
			hot += weight * perhot / 100;
		}
		else if (sign == 'V') {
			cost += su * weight / 100;
			hot += weight * perhot / 100;
		}
		else if (sign == 'R') {
			zhushiweight -= weight;
			if (flag) {
				cost += zhushi * weight / 100;
			}
			else if (zhushiweight < 0) {
				flag = 1;
				cost += (-zhushiweight)*zhushi / 100;
			}
			hot += weight * perhot / 100;
		}
		else if (sign == 'S') {
			cost += tang * weight / 100;
			hot += weight * perhot / 100;
		}
	}
	if (hot < 900) {
		cost *= 0.9;
	}
	cout <<fixed<<setprecision(2)<< cost << endl;
        return 0;
}

2.暴力

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
using namespace std;

int a[1005];
vector<int> ans;
long long fastPower(long long base, long long power) {
	long long result = 1;
	while (power > 0) {
		if (power & 1)
			result = result * base;
		power >>= 1;
		base = base * base;
	}
return result;
}

int main() {
	int N;
	cin >> N;
	long long sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum += fastPower(a[i], 3);
	}
	for (int i = 0; i < N; ++i) {
		if (sum - fastPower(a[i], 3) == a[i]) {
			ans.push_back(a[i]);
		}
	}
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i] << " ";
	}
     return 0;
}

3.结构体排序

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
#include<string>
using namespace std;


struct student{
	string name;
	string id;
	double GPA;
	double jiafen;
	string school;
	student(string pname, string pid, double pGPA, double pjiafen, string pschool) {
		name = pname;
		id = pid;
		GPA = pGPA;
		jiafen = pjiafen;
		school = pschool;
	}
};

vector<student> s;
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		string a, b, e;
		double c, d;
		cin >> a >> b >> c >> d >> e;
		s.push_back(student(a, b, c, d, e));
	}
	sort(s.begin(), s.end(), [](student s1, student s2) {
		return s1.GPA > s2.GPA;
	});
	for (int i = 0; i < M; ++i) {
		cout << s[i].school << " ";
	}
	cout << endl;
	sort(s.begin(), s.end(), [](student s1, student s2) {
		return s1.jiafen > s2.jiafen;
	});
	for (int i = 0; i < M; ++i) {
		cout << s[i].id << " ";
	}
	cout << endl;
	sort(s.begin(), s.end(), [](student s1, student s2) {
		return s1.jiafen+s1.GPA> s2.jiafen+s2.GPA;
	});
	for (int i = 0; i < M; ++i) {
		cout << s[i].name << " ";
	}
	cout << endl;
       return 0;
}

4.字符串+图论,离散化即可

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
#include<string>
using namespace std;


unordered_map<string, int> mp;
int num = 0;
vector<vector<string> > vec(100, vector<string>());
int main() {
	string s,t1,t2;
	cin >> s;
	int i = 0, j = 0;
	while (j < s.size()) {
		if (s[j] == '-') {
			t1 = s.substr(i + 1, j - i - 1);
			if (!mp.count(t1)) {
				mp[t1] = num++;
			}
			i = j;
		}
		else if (s[j] == ']') {
			t2 = s.substr(i + 1, j - i - 1);
			if (!mp.count(t2)) {
				mp[t2] = num++;
			}
			vec[mp[t1]].push_back(t2);
			vec[mp[t2]].push_back(t1);
			i = j + 1;
		}
		++j;
	}
	string tofind;
	cin >> tofind;
	if (!mp.count(tofind)) {
		cout << "NULL" ;
	}
	else {
		int tt = mp[tofind];
		for (int i = 0; i < vec[tt].size(); ++i) {
			cout << vec[tt][i] << " ";
		}
	}
	return 0;
}

5.图论求无向图连通分支,运用并查集可求解

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
#include<string>
using namespace std;


unordered_map<string, int> mp;
unordered_set<int> st;
int num = 0;
struct DSU {
	vector <int> parent;
	vector<int> rank;
	DSU(int n) {
		parent.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; ++i) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int find(int index) {
		return index == parent[index] ? index : parent[index] = find(parent[index]);
	}
	bool union_(int u, int v) {
		int rootu = find(u), rootv = find(v);
		if (rootu == rootv) return 0;
		else {
			if (rank[rootu] > rank[rootv])  parent[rootv] = rootu;
			else if (rank[rootu] < rank[rootv])  parent[rootu] = rootv;
			else {
				parent[rootu] = rootv;
				++rank[rootv];
			}
			return 1;
		}
	}
};

int main() {
	int n;
	cin >> n;
	DSU dsu(105);
	for (int i = 0; i < n; ++i) {
		string s1, s2;
		cin >> s1 >> s2;
		if (!mp.count(s1)) {
			mp[s1] = num++;
			dsu.parent[mp[s1]] = mp[s1];
		}
		if (!mp.count(s2)) {
			mp[s2] = num++;
			dsu.parent[mp[s2]] = mp[s2];
		}
		dsu.union_(mp[s1], mp[s2]);
	}
	for (int i = 0; i < num; ++i) {
		st.insert(dsu.parent[i]);
	}
	cout << st.size();
	return 0;
}

6.计算几何

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct AC{
	int x,y,id;
	double theta;
}point[1010];
bool cmp(AC x,AC y){
	return x.theta<y.theta;
}
double angle(AC o,AC s,AC e) 
{ 
	double cosfi,fi,norm; 
	double dsx = s.x - o.x; 
	double dsy = s.y - o.y; 
	double dex = e.x - o.x; 
	double dey = e.y - o.y; 
	cosfi=dsx*dex+dsy*dey; 
	norm=(dsx*dsx+dsy*dsy)*(dex*dex+dey*dey); 
	cosfi /= sqrt( norm ); 
 
	if (cosfi >=  1.0 ) return 0; 
	if (cosfi <= -1.0 ) return -3.1415926; 
	fi=acos(cosfi); 
	if (dsx*dey-dsy*dex>0) return fi;     
	return -fi; 
}
int main(){
	int n,m,p,t;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>point[i].x>>point[i].y;
		point[i].id=i;
	}
	p=point[m].x;
	t = point[m].y;
	point[m].id=point[n].id;
	point[m].x=point[n].x;
	point[m].y=point[n].y;
	point[n].x=p;
	point[n].y=t;
	for(int i=1;i<n;i++){
		point[0].x=point[n].x+10;
		point[0].y=point[n].y;
		point[i].theta=angle(point[n],point[0],point[i]);
		if(point[i].theta<0){
			point[i].theta+=100;
		}
	}
	sort(point+1,point+n,cmp);
	cout<<point[1].id;
       return 0;
}
南信大程序设计大赛题目及代码 给出n个正整数和一个正整数m,求出这n个正整数中是m的倍数的所有数的平均值。 输入: 输入包含若干组,每组包含三行,第一行为n(n 正整数,第三行为正整数m。如果n为0表示输入结束。 输出: 对每组测试样例输出一行,这n个正整数中是m的倍数的所有数的平均值。 结果小数点后保留2位小数。如果没有满足条件的数,则输出-1 #include #include #include #define N 3 阅读详情

相关推荐

世界编程大赛第一名程序

NULL 博文链接:https://daixj110.iteye.com/blog/954298

C++组2020高校计算机能力挑战赛-决赛赛题解析

第一题 #include<bits/stdc++.h> using namespace std; struct student{ int k; int t; int id; }; bool cmp(struct student &a,struct student &b){ if(a.k*a.t==b.k*b.t){ if(a.t==b.t) return a.id<b.id; else return a.t>b.t; } return

weixin_45689929的博客 2462

2020年全国大学生计算机能力挑战赛官方真题

2020年全国大学生计算机能力挑战赛官方真题;主要涉及程序语言设计、基础语言知识、算法与数据结构题目等

2023团体程序设计天梯赛赛时代码

string s;n += m;io;//int t;cin >> t;return 0;n += m;io;//int t;cin >> t;return 0;n += m;io;//int t;cin >> t;return 0;n += m;io;//int t;cin >> t;return 0;300050。

Suryxin's blogs 1384

世界编程大赛代码

近20年所有获奖代码,很好也很奇葩 https://submit.ioccc.org/ The 21st International Obfuscated C Code Contest The 21st International Obfuscated C Code Contest is open from 2012-Aug-15 03:14:15 UTC to 2012-Sep-14 09:26:53 UTC In order to electronically submit an entry to the 21st IOCCC you must have a valid email address and a browser capable of handling cookies. To verify your email address we will send you an email message containing a submission code and a url to continue submitting your entry using the web. This email address will be used by the IOCCC to contact you. It will not be published. An oportunity to provide an alternate "public" email address will be given if you are a winner! If you wish to submit more than one entry (the rules permit 8 entries per year) you should obtain a new submission code for each one. A submission code expires after 5 days. We recommend that you submit your entry as soon as the submission code arrives! Once you have submitted an entry you can update it as many times as you wish before the competition closes.

代码:编程比赛代码

编程比赛代码

2020年计算机能力挑战赛C/C++初赛题解

若有非零整数A、B、C,将其组成两个等式(A@B)#C=24、A@(B#C)=24,其中@和#为运算符号’+‘、’-‘、’*‘、’/‘、’%'之一,同一符号可选择一次或多次,如果这两个等式至少有一个成立,则输出YES,否则输出NO。输入正整数A、B、C(0

暴力扬 4471

世界编程大赛冠军作品史上最牛代码

作品就叫OMNISCENT 这个程序是97年Mekka ’97 4K Intro比赛的一等奖作品,汇编语言所写。整个程序全长4095字节, 生成.com程序只有4K,可是却实现了3D动画的效果,还有一段背景音乐,画面是游戏天旋地转的一个场景

2021年第三届计算机能力挑战赛C++决赛试题

2021年第三届计算机能力挑战赛C++决赛试题 前言 下面代码都是自己写的,因为做题系统不能立马给出代码的通过情况。所以可能存在有些条件考虑不全面的问题。若发现代码有误,欢迎在评论区指出哦~ 题目 1: 分析:这道题,判断回文就OK #include <iostream> #include <iomanip> #include <cstring> #include <algorithm> #include <sstream> using nam

m0_56836274的博客 2915

本科毕业设计基于Web的大学生计算机设计大赛报名网站的开发源代码.zip

本科毕业设计基于Web的大学生计算机设计大赛报名网站的开发源代码。本项目是因毕业所设计出的一个前后端分离的web应用程序,前端采用Vue框架,后端采用Spring Boot框架、数据库采用MariaDB(可自行更改为其他关系型数据库)。 起初课题名称:基于Web的大学生计算机设计大赛报名网站的设计与实现 而后课题名称:基于Web的大学生计算机设计大赛网站的设计与实现 最终课题名称:基于Web的大学生计算机设计大赛报名网站的开发 使用idea打开BackEnd和FrontEnd,后端需要jdk1.8,前端需要Vue脚手架和npm才可运行,如遇报错请前往/SourceCode/BackEnd文件夹 功能 登录、退出、注册 消息查看、消息删除 报名比赛 消息发布 评审比赛 用户信息修改 搜索比赛 查看评审结果、比赛排名

GPT Researcher 的win docker安装攻略

github网址是:https://github.com/assafelovic/gpt-researcher/blob/master/README-zh_CN.md。使用 Docker 运行 AI-Researcher 项目的。因为docker安装方法不够清晰,因此写一个使用方法。打开设置——docker engine ,增加代码。如有其他问题,可提供错误截图或日志进一步排查!

weixin_43818488的博客 1126

[国一]2024计算机能力挑战赛Java赛项决赛(5道编程大题+题解思路解析)

尽管第一次参赛并未取得理想的成绩,但我从中获得了宝贵的经验教训。这次经历教会了我如何更好地准备比赛,理解到了团队合作的重要性,并且认识到了自身知识体系中的不足之处。更重要的是,它让我明白成功并非一蹴而就,而是需要持续不断的努力和积累。在此过程中,我得到了西安石油大学计算机协会成员们的热情帮助和支持,这无疑是我前进道路上的一大动力源泉。

shaozheng0503的博客 1505

模型性能评估之 Friedman 检验与 Nemenyi 后续检验

前言 当我们提出一种算法,需要知道我们的算法和现在已有的算法相比,性能是否更优的时候,就需要用到模型性能评估的方法。本篇博客介绍一种模型性能评估的方法:Friedman 检验与 Nemenyi 后续检验。 该方法的特点是:可以进行多个算法的比较。下面看看具体的使用: 具体使用 1. 计算序值 假定我们用 D1D_1D1​、D2D_2D2​ 、D3D_3D3​ 和 D4D_4D4​ 四个数据集对算法 AAA、BBB、CCC 进行比较。首先需要得到每个算法在每个数据集上的测试结果,可以是准确率,也可以是均方误差

蕾欧娜与26的博客 1万+

2021第三届全国高校计算机能力挑战赛--程序设计大赛C++代码

决赛共有五题,难度不大。但比赛时时间较为紧张,第4题未完成。这些均为楼主自己写的代码,测试样例可以通过,但不一定能AC,仅供参考 第一题: 简单模拟 #include<bits/stdc++.h> using namespace std; bool judge(string s) { if(s.size()<2) return true; int p=0; int q=s.size()-1; while(p<q) { if(s[p]!=s[q]) return f

Jayden13的博客 2929

Flocking for Multi-Agent Dynamic Systems: Algorithms and Theory的理论简述和python仿真实现(附源码)

经典论文Flocking for Multi-Agent Dynamic Systems: Algorithms and Theory的学习与编程仿真,提供源码

m0_59701926的博客 1238

Mid-360与FAST-LIO2实战:从点云采集到高精度建图全流程解析

本文详细解析了使用Livox Mid-360激光雷达与FAST-LIO2算法实现高精度实时建图的全流程。内容涵盖硬件准备、软件环境搭建、算法部署配置、数据采集实战,并重点探讨了多楼层场景下的参数调优与误差抑制策略,为机器人及无人机三维感知应用提供了实用指南。

prometheus9mon的博客 415

2020/11/29 全国计算机能力挑战赛

记一次惨痛的教训,变量名一定不能记错!!考试时将res错写成下面的stu,导致结果测试错误,痛失60元。 for(int i = 0; i < cnt; i++) { cout << stu[i].xuehao << " "; cout << stu[i].sum << endl; } 原题待后补。 #include <cstdio> #include <cstdlib> #include <iost

菜菜菜菜(;′⌒`) 366

Unity 热更新技术 |(六)xLua框架学习最新系列完整教程

开始学习热更新方面系列知识,就从这一篇开始吧! 本系列教程 会从热更新基本概念出发,详细介绍热更新相关的全套知识点。 如热更新技术基本原理、热更新主流方案、AssetBundle系列教程、Lua语言编程、Lua与Unity交互教程、Xlua框架使用、热更新实战教程等方面。 热更新作为一个开发者必备技能,如果想学习的话,可以从现在开始了哦~ 接下来先从XLua学习使用 开始学习吧!

努力前行,总会成为自己心中的那道光 1万+

第3届83行代码大赛第2关赛题官方解析

简介: 由阿里云云效主办的2021年第3届83行代码挑战赛已经收官。超2万人围观,近4000人参赛,85个团队组团来战。大赛采用游戏闯关玩儿法,融合元宇宙科幻和剧本杀元素,让一众开发者玩得不亦乐乎。 其中大赛第二题,号称魔鬼算法题,拦住诸多代码好汉。 我们请来了第二题的出题人,刘力华(阿里云云效代码平台),为大家系统揭秘,从设计到攻略,还有优秀代码解析供大家参考。 赛题设计 我设计的第二关是希望能考察参赛者的基础算法、数据结构的能力。 设计来源 本赛题采用的是字符串前缀匹配算法,参数者需要先通过OSS获取

BYvonne的博客 4595

MATLAB应用实战系列(四十三)-基于MATLAB的光伏并网系统仿真设计

在Matlab中建立光伏电站接入系统模型,包括光伏发电逆变器及负荷模型等,仿真分析接入点处的电能质量,实现高品质并网运行。 壹 构建太阳能电池模型。 初始化参数如下图所示。 贰 构建MPPT控制模型。 具体封装如下所示: 通过PWM算法实现DC-DC稳步输出最大点。 叁 三、构建直流短距离输电线路。 仿真模型如下图: 通过电容来均衡线路电压,使得线路电压保持可靠性。 肆 通过逆变器变换,使得直流线路转换成...

wenyusuran的专栏 3170

博途PLC S7-1200/1500 ModbusTcp通信SCL代码篇(轮询)

博途PLC MODBUS TCP的详细讲解和注意事项,可以参看下面这篇博文,这里不在赘述。这篇作为SCL代码篇主要给出SCL语言下的轮训写法和注意事项。博途PLC1200/1500PLC ModbusTcp通信(轮询处理)_RXXW_Dor的博客-优快云博客。............

RXXW_Dor的博客 8426

97年的世界黑客编程大赛第一名的作品-Mekka 【代码+使用】

环境 win7系统 使用 1、把这段代码复制下来存为文本文档,命名为1.txt 2、再“运行”——CMD,在窗口中粘贴 debug<1.txt 3、回车 e100 33 f6 bf 0 20 b5 10 f3 a5 8c c8 5 0 2 50 68 13 1 cb e 1f be a1 1 bf 0 1 e11b 6 57 b8 11 1 bb 21 13 89 7 4b 4b 48 79 f9 ad 86 e0 8b c8 bd ff ff e8 20 e134 0 3d 0 1 74 1a 7f

Coder的博客 6415

华为od统一考试B卷【单词搜索】C++ 实现

找到它是一个小游戏,你需要在一个矩阵中找到给定的单词。假设给定单词 HELLOWORD,在矩阵中只要能找到 H->E->L->L->O->W->O->R->L->D连成的单词,就算通过。意区分英文字母大小写,并且您只能上下左右行走,不能走回头路。

MISAYAONE的博客 712

2022年计算机设计大赛国三 数据可视化 疫情看板(源码可分享)

2022年全国大学生计算机设计大赛信息可视化省一、国三 《疫情之下 数据至上》

weixin_52041224的博客 7187

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

计算机设计大赛材料准备讲解

计算机设计大赛材料描述,冲冲冲

nimo观察者 1万+

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

[附源码]SSM计算机毕业设计学院竞赛管理信息系统JAVA

竞赛信息管理,管理员可在竞赛信息管理页面查看竞赛编号、竞赛名称、项目类型、竞赛要求、费用、比赛时间、封面、比赛地点、教师账号、教师姓名等内容,还可进行添加、修改或删除等操作,如图。比赛报名,学生可通过输入竞赛编号、竞赛名称、费用、报名时间、学号、姓名、教师账号、教师姓名、报名原因等内容进行提交等操作,如图。或者 Mac OS;

计算机程序源码 387

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

上一篇: leetcode640求解方程C++代码
下一篇: Latex期末报告——朴素贝叶斯法
RealWeakCoder
博客等级 码龄7年 236粉丝 68原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值