cstring

CF1342C Yet Another Counting Problem

六眼飞鱼酱① 提交于 2020-04-28 16:10:37
Yet Another Counting Problem 思路:假设a <= b。 x % a % b = x % a是显然成立的,那么只需要比较 x % a != x % b % a的情况就可。 通过手写 x % a 和 x % b % a的情况,发现我们只需要写出一个lcm(a,b)的表格(lcm最小公倍数),就是一个循环表, 有了循环表,我们只需要统计一个循环表中每个位置不同余数的个数就可以,我们就可以处理1e18的数据了。 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <functional> 5 #include < set > 6 #include <vector> 7 #include <queue> 8 #include <cstring> 9 10 11 using namespace std; 12 13 #define ll long long 14 #define pb push_back 15 #define fi first 16 #define se second 17 18 const int N = 1010 ; 19 const int INF = 1e9; 20 21 int gcd( int a, int b){ 22 return b

[c++] Why should I use Smart Pointers

感情迁移 提交于 2020-04-26 14:57:45
深入理解智能指针 专有指针 Ref: unique_ptr的使用和陷阱 一、初始化 只可以使用new来分配内存,不可 拷贝和赋值。 unique_ptr< int > up1( new int ()); // okay,直接初始化 unique_ptr < int > up2 = new int (); // error! 构造函数是 explicit unique_ptr < int > up3(up1); // error! 不允许拷贝 二、基本操作 unique_ptr<T> up 空的unique_ptr,可以指向类型为T的对象,默认使用delete来释放内存 unique_ptr <T,D> up(d) 空的unique_ptr同上,接受一个D类型的删除器d,使用删除器d来释放内存 up = nullptr 释放up指向的对象,将up置为空 up.release() up放弃对它所指对象的控制权,并返回保存的指针,将up置为空,不会释放内存 up.reset(…) 参数可以为 空、内置指针,先将up所指对象释放,然后重置up的值. View Code 三、参数、返回值 unique_ptr不可拷贝和赋值,那要怎样传递unique_ptr参数和返回unique_ptr呢? 事实上不能拷贝unique_ptr的规则有一个例外:我们可以拷贝或赋值一个将要被销毁的unique

【PAT】1015 德才论 (25)(25 分)

折月煮酒 提交于 2020-04-26 05:34:43
  1015 德才论 (25)(25 分) 宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。” 现给出一批考生的德才分数,请根据司马光的理论给出录取排名。 输入格式: 输入第1行给出3个正整数,分别为:N(<=10^5^),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。 随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。 输出格式: 输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。 输入样例

Dice (III) (数学期望)

守給你的承諾、 提交于 2020-04-26 05:33:08
Dice (III) LightOJ - 1248 Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that means when you throw the dice, the probability of occurring any face is equal. For example, for a fair two sided coin, the result is 3. Because when you first throw the coin, you will definitely see a new face. If you throw the coin again, the chance of getting the opposite side is 0.5, and the chance of getting the same side is 0.5. So, the result is 1 + (1 + 0.5 * (1 + 0.5 * ...)) = 2 + 0.5 + 0.5

LightOJ

爷,独闯天下 提交于 2020-04-26 04:43:19
题意:   1、两只老虎相遇 就互相残杀   2、老虎与鹿相遇 鹿死   3、老虎与人相遇 人死   4、人与鹿相遇 鹿死   5、鹿与鹿相遇 无果 求人活的概率 解析:如果老虎为0 则人活得概率为1     如果老虎为奇数 因为只有两只老虎相遇的时候 老虎才能死 所以必然是两个两个一起死 所以 最后必然剩一只老虎 所以人死 活得概率为0     如果老虎为偶数 每天不让老虎和人相遇即可 等到所有老虎都相遇 互相残杀之后 人不就是活的了吗 而且鹿的数量 并不能影响人的存活率 因为鹿并不能减少老虎的数量 所以 如果老虎为偶数 则我们把所有老虎都相遇的概率求出来即可    设 老虎 有 x 个    则一对老虎相遇的概率为 C(1,x)/(x+1) * C(1,x-1)/(x)     所有老虎相遇的概率为 C(1,x)/(x+1) * C(1,x-1)/(x) * C(1,x-2)/(x-1) * C(1,x-3)/(x-2) * `````* C(1,2)/3 * C(1,1)/2 化简为 1/(x+1) 代码如下: #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn = 10010 ; int main() { int T,n,k; scanf(

PAT L1-043. 阅览室

泄露秘密 提交于 2020-04-25 13:21:46
L1-043. 阅览室 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下S键,程序开始计时;当读者还书时,管理员输入书号并按下E键,程序结束计时。书号为不超过1000的正整数。当管理员将0作为书号输入时,表示一天工作结束,你的程序应输出当天的读者借书次数和平均阅读时间。 注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有S没有E,或者只有E没有S的纪录,系统应能自动忽略这种无效纪录。另外,题目保证书号是书的唯一标识,同一本书在任何时间区间内只可能被一位读者借阅。 输入格式: 输入在第一行给出一个正整数N(<= 10),随后给出N天的纪录。每天的纪录由若干次借阅操作组成,每次操作占一行,格式为: 书号([1, 1000]内的整数) 键值(“S”或“E”) 发生时间(hh:mm,其中hh是[0,23]内的整数,mm是[0, 59]内整数) 每一天的纪录保证按时间递增的顺序给出。 输出格式: 对每天的纪录,在一行中输出当天的读者借书次数和平均阅读时间(以分钟为单位的精确到个位的整数时间)。 输入样例: 3 1 S 08:10 2 S 08:35 1 E 10:00 2 E 13:16 0 S 17:00 0 S 17:00 3

从Student类和Teacher类多重派生Graduate类 代码参考

廉价感情. 提交于 2020-04-23 07:18:58
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 class Person 7 { 8 private : 9 char Name[ 10 ]; 10 char Sex; 11 int Age; 12 public : 13 void Register( char *name, int age, char sex); 14 void ShowMe(); 15 }; 16 17 void Person::Register( char *name, int age, char sex) 18 { 19 strcpy(Name,name); 20 Age= age; 21 Sex= sex; 22 return ; 23 } 24 25 void Person::ShowMe() 26 { 27 cout<< " 姓名 " <<Name<< endl; 28 if (Sex== ' m ' ) cout<< " 性别 男 " << endl; 29 else cout<< " 性别 女 " << endl; 30 cout<< " 年龄 " <<Age<< endl; 31 return ; 32 } 33 34 class Teacher: public Person 35 { 36

一个基类Person的多个派生类 代码参考

☆樱花仙子☆ 提交于 2020-04-23 03:36:17
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 class Person 7 { 8 protected : 9 char Name[ 10 ]; 10 char Sex; 11 int Age; 12 public : 13 void Register( char *name, int age, char sex); 14 void ShowMe(); 15 }; 16 17 class Teacher: public Person 18 { 19 private : 20 char Dept[ 20 ]; 21 int Salary; 22 public : 23 Teacher( char *dept, int salary, char *name, char sex, int age); 24 void showme(); 25 }; 26 27 class Student: public Person 28 { 29 private : 30 char ID[ 12 ]; 31 char Class[ 12 ]; 32 public : 33 Student( char *name, int age, char sex, char *id, char * classid);

派生类Student的构造函数和析构函数 代码参考

自闭症网瘾萝莉.ら 提交于 2020-04-22 14:57:29
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 class Person 7 { 8 private : 9 char Name[ 10 ]; 10 int Age; 11 public : 12 Person( char *name, int age) 13 { 14 strcpy(Name,name); 15 Age= age; 16 cout<< " constructor of person " <<Name<< endl; 17 } 18 ~Person(){cout<< " deconstructor of person " <<Name<< endl;} 19 }; 20 21 class Student: public Person 22 { 23 private : 24 char ClassName[ 10 ]; 25 Person Monitor; 26 public : 27 Student( char *name, int age, char *classname, char *name1, int age1); 28 ~ Student(); 29 }; 30 31 Student::Student( char *name, int age, char

公有继承中派生类Student对基类Person成员的访问 代码参考

六月ゝ 毕业季﹏ 提交于 2020-04-22 00:57:03
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 class Person 7 { 8 private : 9 char Name[ 20 ]; 10 char Sex; 11 int Age; 12 public : 13 void Register( char *name, int age, char sex); 14 void ShowMe(); 15 }; 16 17 class Student: public Person 18 { 19 private : 20 int Number; 21 char ClassName[ 10 ]; 22 public : 23 void RegisterStu( char *classname, int number, char *name, int age, char sex); 24 void ShowStu(); 25 }; 26 27 void Person::Register( char *name, int age, char sex) 28 { 29 strcpy(Name,name); 30 Age= age; 31 Sex= sex; 32 return ; 33 } 34 void Person::ShowMe() 35