算法
文章平均质量分 58
成为大牛
小白开始
展开
-
A1120
代码#include <iostream>#include <set>//insert插入 using namespace std;int getFriendNum(int a){ int sum = 0; while(a != 0){ sum += a%10; a /= 10; } return sum;}int main(){ set<int> s; int n,a; cin>>n; for(int i = 0; i原创 2021-03-04 16:29:24 · 101 阅读 · 1 评论 -
A1075
题目The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input file contains one test case. For each case, the first line con原创 2021-02-17 16:48:38 · 69 阅读 · 0 评论 -
PAT甲级——A1055 The World‘s Richest
题目Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world’s wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net原创 2021-02-17 12:21:08 · 89 阅读 · 0 评论 -
A1028
题目1028 List Sorting (25point(s))Excel can sort records according to any column. Now you are supposed to imitate this function.Input Specification:Each input file contains one test case. For each case, the first line contains two integers N (≤105) an原创 2021-02-11 09:35:55 · 75 阅读 · 0 评论 -
A1021
题目A1012. The Best RankTo 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 Linear Algebra), and E - English. At the mean time, we encou原创 2021-01-30 18:24:44 · 85 阅读 · 0 评论 -
B1015
题目宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”原创 2021-01-29 18:29:30 · 103 阅读 · 0 评论 -
A1025
题目Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is y原创 2021-01-29 17:38:14 · 87 阅读 · 0 评论 -
sort()函数
选择与直接插入排序void select(){ for(int i = 0; i < n; i++){ int k = i; for(int j = i; j < n ; j++){ if(A[k] > A[j]){//找最小 k = j;//留下标 } } int temp = A[i];//交换A[i]和A[j] A[] }}int A[max],n;void insert(){ for(int i = 1; i <原创 2021-01-28 18:49:00 · 367 阅读 · 0 评论 -
A1006
题目【PAT】PAT A-1006 Sign In and Sign Out【简单模拟】昵称五个字 2019-04-08 15:07:23 438 收藏分类专栏: PAT 文章标签: PAT PAT甲级 算法题版权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原创 2021-01-27 16:00:41 · 77 阅读 · 0 评论 -
B1028
题目1028 人口普查 (20分)某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 年 9 月 6 日,所以超过 200 岁的生日和未出生的生日都是不合理的,应该被过滤掉。输入格式:输入在第一行给出正整数 N,取值在(0,105];随后 N 行,每行给出 1 个人的姓名(由不超过 5 个英文字母组成的字符串)、以及按 yyyy/mm/dd(即年原创 2021-01-26 19:00:19 · 76 阅读 · 0 评论 -
select sort
题目代码void selectSort(){ for(int i = 0; i < n; i++){//进行n趟操作 int k = i; for(int j = i; j <n; j++){//找出从i->n中最小的 if(A[j] < A[k]) k = j; } } int temp = A[i];//交换A[i]和A[j] A[i] = A[j]; A[j] = temp; }``...原创 2021-01-26 18:10:12 · 74 阅读 · 0 评论 -
B1004
题目B1004 成绩排名读入 n(>)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。输入格式:每个测试输入包含 1 个测试用例,格式为第 1 行:正整数 n第 2 行:第 1 个学生的姓名 学号 成绩第 3 行:第 2 个学生的姓名 学号 成绩… … …第 n+1 行:第 n 个学生的姓名 学号 成绩其中姓名和学号均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。输出格式:对每个原创 2021-01-26 18:00:25 · 96 阅读 · 0 评论 -
B1041
题目每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。输入格式:输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个原创 2021-01-26 17:42:01 · 92 阅读 · 0 评论 -
A1002
题目PAT-A1002. A+B for Polynomials (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThis time, you are supposed to find A+B where A and B are two polynomials.InputEach input file contains one test case. Each case occupies 2 lines,原创 2021-01-26 15:10:56 · 89 阅读 · 0 评论 -
A1046
题目1046 Shortest Distance (20分)The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For eac原创 2021-01-19 16:44:14 · 98 阅读 · 0 评论 -
A1042
题目1042 Shuffling Machine (20 分)Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequa原创 2021-01-19 15:18:54 · 72 阅读 · 0 评论 -
B1012
题目代码#include<cstdio>int main(){ int count[] = {0}; int ans[] ={0}; int temp, n; scanf("%d",&n); while(n--){ scanf("%d",&temp); if(temp%5==0){//A1 if(temp%2==0){ count[0]++; ans[0] += temp;原创 2021-01-18 16:28:22 · 46 阅读 · 0 评论 -
B1011
题目代码#include<cstdio>int main(){ int T,i=1; //i代表第几个测试样例了 scanf("%d",&T); while(T--){ long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); if(a+b > c){ printf("Case #%d: true\n",i++); }else{ printf("Case #%d: false原创 2021-01-16 15:07:35 · 59 阅读 · 0 评论 -
B1032
题目代码#include<cstdio>const int maxn = 100010;//初始化数组10^5个index int school[maxn] = {0};//将其都赋值为零 int main(){ int n,score,schID=0; scanf("%d",&n); for(int i = 0;i < n; i++){ scanf("%d",&schID); scanf("%d",&score); school[sc原创 2021-01-12 17:30:16 · 74 阅读 · 0 评论 -
算法笔记B001
题目代码#include<cstdio> int main(){ int n ,i=0; scanf("%d",&n); while(n != 1){ if(n%2==0){ n = n/2; } else{ n = (3*n+1)/2; //要将其赋值给n; } i++; } return i;}结果原创 2021-01-12 16:55:11 · 63 阅读 · 0 评论 -
2020-10-05
讨论1.6 算法3的空间复杂度是多少?老师参与具体来说,这个问题分两部分:由于递归而产生的空间复杂度是多少?算法的整体空间复杂度一共是多少?分而治之的算法时间复杂度T(N)=2T(N/2)+O(N)=2(2T(N/(2^2))+cN/2)+cN=2^kO(1)+ckN其中N/(2^k)=1k=log2(N)1.空间复杂度1.整体假如 n 个数据,中间一分为二,求左边空间要 n/2,右边也是一样。跨越分界线的部分需要扫描一遍左边和右边,加起来是 n所以总共是 S(n) = 2原创 2020-10-05 21:18:29 · 241 阅读 · 0 评论 -
二分法分析
时间复杂度:最好情况下,一击命中,为常数级时间C;最坏情况下,一直二分到剩一个元素,则时间复杂度为log2N空间复杂度:最好情况下,一击命中,不用后续递归,即不用占用调用函数时函数栈的空间,此时空间复杂度为 C 最坏情况下,一直递归二分,需要二分log2N次,即调用函数log2N次,此时空间复杂度为C * log2N时间复杂度计算(看运行次数最多的那条语句被运行了多少次)O(2n)O(2^n)O(2n),表示一个算法的性能会随着输入数据的每次增加而增大两倍,典..原创 2020-10-05 10:16:26 · 1011 阅读 · 0 评论 -
讨论1.3 再试一个多项式
#include<stdio.h>#include<math.h>#include<time.h>#声明clock_t start,stop;double duration;double f1(double x);double f2(double x);int main(){ start = clock(); for(int i = 0;i<10000;i++)#时间过短,加长好比较 f1(1.1); stop = clock(); .原创 2020-10-05 09:34:04 · 153 阅读 · 0 评论 -
2.1线性表
2.1.1多项式的表示f(x)=a0+a1x+…+a[n-1]*x^(n-1)+ a[n]*x的n次方如何表达 :A[i]指数i多项式项数n顺序存储结构1.直接表示令n=i问题:表示x+x^345的空间资源过于浪费2.只表示非零项,将多项式项数看成二元表(n,A[i])用结构数组表示:数组分量是由指数,系数组成的结构3.运算方便按照指数大小有序存储链表结构储存非零项链表包括每个结点储存多项式中的一个非零项;包括系数和指数两个数据域和一个指针域...原创 2020-09-27 22:17:31 · 216 阅读 · 1 评论 -
陈越mooc1.3
1.31.3.1最大子列和问题算法11.从1-i个数开头求和2.如果当前大就赋值3.加完比完后MaxSum更新为0int MaxSubseqSum1(int A[], int N){ int Max = 0; int Current = 0 int i,j,k =0; for(i = 0;i<N;i++) { Current = 0; for(j = i;j<N;j++) {原创 2020-09-23 11:14:44 · 101 阅读 · 0 评论 -
算法4中视频1.3节栈(对象游离)loitering
对象游离(loitering)定义:即在栈的数组实现中有对象的引用,而我们并没有真正使用它,所以当减小N时,在数组中仍然有我们已经出栈的对象的指针。尽管我们知道我们不再使用它了,但是Java系统不知道解决:最好将去除元素对应的项设为null,这样就不会剩下...原创 2021-01-18 16:29:39 · 114 阅读 · 0 评论 -
search a 2D matrix 2
https://leetcode-cn.com/problems/search-a-2d-matrix-ii/原创 2020-02-22 20:04:25 · 72 阅读 · 0 评论 -
排序
bubble sort从后往前排序选择排序一直找相当最小的往前排插入排序i与ji确定排序的位置j与j-1比较取最小因为是插入,所以为前到后排序shell 排序基础为插入排序,j-1 -》j-hh为自定义...原创 2020-02-20 17:21:16 · 54 阅读 · 0 评论 -
leetcode 78. Subsets
递归//思路递归class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList();//最终结果集合 List<Integer> temp...原创 2020-02-15 18:56:02 · 66 阅读 · 0 评论 -
3-递归和分治
递归三要素:从定义上来看是递归1.递归定义:什么样的参数返回什么样的值做了什么2.怎么拆分问题3.结束条件`/*Definition for binery treepublic class TreeNode{int val;TreeNode left;TreeNode right;TreeNode(int x ){val = x;}}*///递归方法Traverse一套...原创 2020-02-14 19:04:27 · 78 阅读 · 0 评论 -
2——二分法
二分法模板class Solution { /* @param nums: An interger array sorted in ascending order @param target: An interger @return an integer */ public int lastPosition(int[] nums, int targ...原创 2020-02-11 19:58:47 · 84 阅读 · 0 评论 -
1——基础第一节
28. Implement strStr()(https://leetcode.com/problems/implement-strstr/)1.暴力法class Solution { /* .Returns a index to the first occurence of target in source, .or -1 if target is not part...原创 2020-02-08 16:17:24 · 129 阅读 · 0 评论