ACM队内Rating赛题解报告(七)
CF699A - Launch of Collider题目描述There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coord ...
ACM队内Rating赛题解报告(六)
CF1041A - Heist题目描述There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x=4 and there were 3 keyboards in the store, then the devices had indices 4, 5 and 6, and if x=10 and there were 7 of them then the keyboards had indices 10, 11, 12, 13, 14, 15 and 16.
After the heist, only n keyboards remain, and they have indices a1,a2,…,an. Calculate the minimum possible number of keyboa ...
ACM队内Rating赛题解报告(五)
CF1047A - Little C Loves 3 I题目描述Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
输入A single line containing one integer n (3≤n≤10^9^) — the integer Little C has.
输出Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at l ...
快速入门C++(四):封装、继承和多态
前言🎡前面几篇文章介绍了C++面向对象的基础,本篇将介绍面向对象最重要的部分。
🎃它是所有采用面向对象思想的编程语言的核心:封装、基础和多态。
🎉面向对象思想需要通过实践学习,仅仅通过文字描述很难理解它的本质。
封装🎡封装指将数据成员私有化,通过成员函数的形式访问数据成员。
🎃封装的特点是降低各模块间的耦合度、提高可维护性,避免错误的发生。
下面通过一个例子说明为什么需要封装:
12345678910111213141516171819#include <iostream>using namespace std;class Student{public: int age;};int main(){ Student student; student.age = -1; cout << student.age << endl; return 0;}
输出结果:
1-1
🎡首先,直接对数据成员进行访问,不利于模块独立化,也不利于后期的维护。
🎃其次,对age数据成员赋值-1显然不符合逻辑。
采用封装 ...
ACM队内Rating赛题解报告(四)
CF796A - Buying A House题目描述Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house m of a village. There are n houses in that village, lining in a straight line from left to right: house 1, house 2, …, house n. The village is also well-structured: house i and house i + 1 (1 ≤ i < n) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchas ...
快速入门C++(三)构造函数和析构函数
前言🎃本文介绍C++中构造函数和析构函数。
😋C++中常用构造函数进行对象创建时的初始化操作。
🤨析构函数则相反,用于处理对象销毁后的善后工作。
构造函数🎉构造函数是一种特殊的成员函数,创建对象时自动调用构造函数。
🎃根据构造函数的特性,我们可以使用构造函数来进行初始化操作。
😋如果我们没有为类定义构造函数,编译器会默认提供一个默认构造函数(无参数,不进行任何操作,仅仅满足接口要求)。
构造函数的特点:
构造函数名和类名相同
构造函数没有返回值
定义构造函数声明构造函数的方法(类名即函数名):
1类名(参数);
定义构造函数的方法:
1234类型::类名(参数){ 函数体;}
🎃下面,通过一个例子说明:
12345678910111213141516171819202122232425#include <iostream>using namespace std;class Student{public: int age; int grade; Student(int age); //声明构造函数};St ...
快速入门C++(二):函数重载和运算符重载
前言😋本文主要讲述C++中关于函数重载和运算符重载的一些基础知识。
🎡系统的梳理一下C++的相关知识,为后面的知识打下基础。
🧶重载提高了C++代码的复用性,节省了我们大量时间精力。
(从本文开始使用C++的输出输出方式,即iostream头文件定义的方式)
函数重载🎡函数重载是指在同一个作用域内定义多个函数名相同但形参不同的函数,即同名函数实现不同函数功能。
❗注意!必须是参数不同才可以重载(参数不同可以是个数、类型、顺序不同)。
下面通过一个例子说明函数重载:
123456789101112131415161718192021222324#include <iostream>using namespace std;void judge(int a); //参数int类型void judge(double a); //参数double类型int main(){ judge(1); //传递一个int类型的参数 judge(1.0); //传递一个double类型的参数 return 0;}void judge(int a){ c ...
快速入门C++(一):类
前言🎃C++是基于C语言衍生的一门语言。它的特色在于面向对象、泛型编程和提供的强大的STL(标准模板库)。
🎈提到面向对象思想,不免想到封装、继承和多态,这是面向对象的三大特性,面向对象的基础是类。
🎡面向对象仅仅靠几句话是无法理解的,必须通过实践才能体会面向对象的优势所在。
🐾本文系统的梳理一下面向对象的基础—类。
注意:本文以介绍类为主,尽量不使用C++中的STL。如string使用了char数组进行代替。
类类的定义🎉万物皆是对象,类是对具有共同特征的一类对象的抽象。
🧧共同特征分为:属性特征(数据成员)和行为特征(成员函数)。
C++中类的定义格式:
123456class 类名{成员访问控制符: 数据成员 成员函数};
🧑下面以学生为例,定义一个Student类。
学生的共同属性有:姓名、年龄、考试成绩
共同行为有:学习。
123456789class Student //类名:Student{public: //成员访问控制符:public char name[20]; //数据成员:name int age; //数据成 ...
ACM队内Rating赛题解报告(三)
CF991A - If at first you don’t succeed…题目描述Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn’t pass it. However, many of Vasya’s fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn’t pass ...
ACM队内Rating赛题解报告(二)
CF994A - Fingerprints题目描述You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
输入The first line contains two integer ...