
C++
Scarlett·S
学海无涯,回头无岸
展开
-
第一次竞赛-D.量子能力猫
猫从薛定谔的箱子里成功存活并逃脱出来,这时它发现它已经掌握了量子力学的原理并拥有运用量子的能力。即便这样它还是克服不了它喜欢钻入纸箱的天性。假设现在有一排纸箱的一端从0开始依次编号,这只猫可以以如下的方式在箱子之间行动:走到相邻箱子:从第X号箱子走到相邻的第X+1号或X-1号箱子。 量子形式转移:从第X号箱子以量子态形式转移到2X号箱子里。不论是用走的方法还是量子转移的方法,都算作一次转...原创 2019-01-20 22:02:21 · 220 阅读 · 0 评论 -
PAT1-第39级台阶(递归)
第39级台阶小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!站在台阶前,他突然又想着一个问题:如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?请你利用计算机的优势,帮助小明寻找答案。要求提交的是一个整数。注意:不要提交解答过程,...原创 2018-02-18 22:31:51 · 313 阅读 · 0 评论 -
放苹果-递归
#include<iostream>using namespace std;int f(int m,int n) {//边界 if(n == 0) return 0; if(m == 0) //不放苹果时返回1,因为允许有空盘 return 1; //递归if(n > m) return f(m,m); return f(m,n-1)+f...原创 2019-02-24 13:30:31 · 209 阅读 · 0 评论 -
C++ Pat甲级1009 Product of Polynomials (25 分)
1009 Product of Polynomials (25 分)多项式的积This time, you are supposed to find A×B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 ...原创 2019-02-24 14:41:29 · 446 阅读 · 0 评论 -
C++ Pat甲级1010 Radix (25 分)(auto,rbegin(),rend(),max_element())
1010 Radix (25 分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pa...原创 2019-02-24 16:53:08 · 233 阅读 · 0 评论 -
C++ Pat甲级1003 Emergency (25 分)图+dfs
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...原创 2019-02-23 13:39:31 · 535 阅读 · 0 评论 -
递归-汉诺塔
#include <iostream>#include <cstdio>using namespace std;void Hanoi(int n,char src,char mid,char dest) { if(n==1) { cout <<src<<"->"<<dest<<endl;原创 2019-02-14 12:40:07 · 140 阅读 · 0 评论 -
C++ Pat甲级1011 World Cup Betting (20 分)
1011 World Cup Betting (20 分)With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World...原创 2019-02-25 19:08:53 · 194 阅读 · 0 评论 -
C++ Pat甲级1012 The Best Rank (25 分)(利用结构体里加数组来排名)
1012The Best Rank(25 分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or L...原创 2019-03-01 17:15:00 · 162 阅读 · 0 评论 -
C++ Pat甲级1013 Battle Over Cities (25 分)(求图的连通分量dfs)
1013Battle Over Cities(25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We...原创 2019-03-01 20:40:29 · 200 阅读 · 0 评论 -
寻找指定和的整数对-二分
输入n(n<=100000)个整数,找出其中两个数,(假设一定有解),使他们的和等于m.#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main() { int n,m; int a[100000]; cin >>...原创 2019-03-19 21:10:30 · 771 阅读 · 0 评论 -
农夫和奶牛-二分(未完成没搞懂题目)
农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1,000,000,000).但是,John的C (2 <= C <= N)头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争斗。为了不让牛互相伤害。John决定自己给牛分配隔间,使任意两...原创 2019-03-19 21:54:11 · 1734 阅读 · 1 评论 -
灰灰-1081-检查密码
本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点.,还必须既有字母也有数字。输入格式:输入第一行给出一个正整数 N(≤100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。输出格式:对每个用户的密码,在一行中输出系统反馈信息,分以下5种...原创 2019-03-20 00:20:52 · 185 阅读 · 0 评论 -
灰灰-325-326-327-2019中南大学计算机上机-走台阶(3)
(1)n个台阶,一次走1阶或2阶,问走n阶有多少可能?(1<=n<=1000 000)结果用1000 0000 7取模输出。输入格式:输入台阶数n输出格式:结果用1000 0000 7取模输出。输入样例:3输出样例:3#include <iostream>using namespace std;int f(int n) {...原创 2019-04-11 12:08:24 · 249 阅读 · 0 评论 -
C++ Pat甲级1008 Elevator (20 分)
1008 Elevator (20 分)The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified...原创 2019-02-23 20:46:28 · 181 阅读 · 0 评论 -
C++ Pat甲级1007 Maximum Subsequence Sum (25 分)(dp)
1007 Maximum Subsequence Sum (25 分)Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1≤i≤j≤K. The Maximum Su...原创 2019-02-23 20:12:02 · 248 阅读 · 0 评论 -
第一次竞赛-E.找饭友
中国幅员辽阔,来自全国各地的朋友的饮食口味也不尽相同。饮食喜好相同的人会组在一起吃饭,我们称其互为“饭友”。而你意外得到了一份食堂的流水账单记录,想从中发现今天来食堂吃饭的人当中每个人究竟有多少名饭友。 首先你对账单的记录进行了一番整理,把N个消费者依次编号为1,2,…,N,把M种食品依次编号为1,2,…,M。为简单起见,认为喜欢吃同一种食品的人,就是他的饭友。你现在的任务是从这份账单记录中计算...原创 2019-01-20 22:13:50 · 212 阅读 · 0 评论 -
递归-n皇后
#include <iostream>#include <cmath>using namespace std;int N;int queenPos[100];void NQueen(int k);int main(void) { cin >> N; NQueen(0); return 0;}void NQueen(int ...原创 2019-02-14 21:46:16 · 179 阅读 · 0 评论 -
关于cstdio和iostream,以及有关namespaces的问题
1.cstdio是面向“文件”的,或者不强调文件和非文件流的区别,默认流就是可以关联外部文件,至于文件的外延是啥就不管,扔给宿主环境了。从std::FILE这个名字以及printf/scanf接口描述基于fprintf/fscanf上就可以看出来。iostream头只是包含了一坨东西,封装标准输入输出流,和文件流(在<fstream>)不通用。2.cstdio不知道iostream...原创 2019-02-10 19:54:19 · 5711 阅读 · 0 评论 -
C++生理周期(枚举)
描述:人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23 天、 28 天和33 天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同一天。对于每个周期,我们会给出从当前年份的第一天开始,到出现高峰的天数(不...原创 2019-02-10 20:51:52 · 1021 阅读 · 0 评论 -
C++称硬币(枚举)
有12枚硬币。其中有11枚真币和1枚假币。假币和真币重量不同,但不知道假币比真币轻还是重。现在,用一架天平称了这些币三次,告诉你称的结果,请你找出假币并且确定假币是轻是重(数据保证一定能找出来)。 输入第一行是测试数据组数。每组数据有三行,每行表示一次称量的结果。银币标号为A-L。每次称量的结果用三个以空格隔开的字符串表示:天平左边放置的硬币、天平右边放置的硬币、平衡状态。其中平衡状态用`...原创 2019-02-10 22:05:37 · 875 阅读 · 0 评论 -
C++ 熄灯问题poj1222:EXTENDED LIGHTS OUT
1222:EXTENDED LIGHTS OUT描述In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5 rows of 5 buttons each). Each button has a light. When a...原创 2019-02-10 23:07:20 · 716 阅读 · 0 评论 -
C++甲级1001 A+B Format (20 分)(sprintf,memset,reverse)
1001 A+B Format (20 分)Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Spe...原创 2019-02-11 22:08:16 · 382 阅读 · 0 评论 -
逆波兰表达式-递归
#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;double exp() { char s[20]; cin >> s; switch(s[0]) { case '+': return exp()+exp(); case ...原创 2019-02-22 15:42:22 · 503 阅读 · 0 评论 -
C++甲级1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分)This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, a...原创 2019-02-13 23:23:15 · 271 阅读 · 0 评论 -
表达式求值-递归
表达式由项组成(+ -)项由因子组成(* /) #include <cstring>#include <cstdlib>#include <iostream>using namespace std;int factor_value();//求一个因子的值int term_value();//求一个项的值int express...原创 2019-02-23 13:03:14 · 425 阅读 · 0 评论 -
C++ Pat甲级1004 Counting Leaves (30 分)树+vector+dfs
1004 Counting Leaves (30 分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains on...转载 2019-02-23 15:41:35 · 165 阅读 · 0 评论 -
C++ Pat甲级1005 Spell It Right (20 分)(to_string)
1005 Spell It Right (20 分)Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file...原创 2019-02-23 16:31:40 · 152 阅读 · 0 评论 -
C++ Pat甲级1006 Sign In and Sign Out (25 分)(字符串strcmp , strcpy)
1006 Sign In and Sign Out (25 分)At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the reco...原创 2019-02-23 17:22:41 · 260 阅读 · 0 评论 -
灰灰-328-LeetCode682棒球比赛(vector、stack、atio()、substr()、c_str()、accumulate())
你现在是棒球比赛记录员。给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数。2."+"(一轮的得分):表示本轮获得的得分是前两轮有效回合得分的总和。3."D"(一轮的得分):表示本轮获得的得分是前一轮有效回合得分的两倍。4."C"(一个操作,这不是一个回合的分数):表示您获得的最后一个有效回合的分数是无效的,应该被移除...原创 2019-04-11 14:34:09 · 198 阅读 · 0 评论