- 博客(48)
- 资源 (1)
- 收藏
- 关注
原创 2018计蒜客之道初赛
小明刚刚入职淘宝,老大给他交代了一个简单的任务,实现一个简易的商品推荐系统。这个商品推荐系统的需求如下:一共有 n 件商品可以被推荐,他们的编号分别为 1 到 n。每件商品都有一个价格,编号为 i 的商品价格为 pi 元。现在需要给用户推荐尽可能多的商品,但是要保证按照编号上升的顺序给用户依次推荐商品,并且,相邻商品的价格之差的绝对值不能超过 d。注意,第一个推荐的商品价格没有限制。...
2018-05-14 09:37:17
551
原创 CF 2018, XI Samara Regional Intercollegiate Programming Contest 习题总结
题目:A. Restoring NumbersPavel had two positive integers a and b. He found their sum s and greatest common divisor g, and forgot a and b after that. Help him to restore the original numbers.InputA ...
2018-04-26 21:28:14
319
原创 CF 2018, XI Samara Regional Intercollegiate Programming Contest 习题总结
题目:A. Restoring NumbersPavel had two positive integers a and b. He found their sum s and greatest common divisor g, and forgot a and b after that. Help him to restore the original numbers.InputA ...
2018-04-18 11:57:40
893
原创 2018CCCC天梯赛整理
L1-049. 天梯赛座位分配天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情。为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位参赛选手。令每校选手排成一列纵队,第 i+1 队的选手排在第 i 队选手之后。从第 1 所学校开始,各校的第 1 位队员顺次入座,然后是各校的第 2 位队员…… ...
2018-04-03 19:47:34
5672
原创 二叉树整理
/* * 分别用递归和非递归方式实现二叉树先序、中序和后序遍历 【题目】 用递归和非递归方式,分别按照二叉树先序、中序和后序打印所有的节点。 * 我们约定:先序遍历顺序为根、左、右;中序遍历顺序为左、根、右;后序遍历顺序为左、右、根。 */ 二叉树样例: 递归的过程: 1 2 4 4 4 2 5 5 5 2 1 3 6 6 6 3 7 7 7 3 1 由上可知每个节点访...
2018-04-03 16:53:44
175
原创 Codeforces Round #467 (Div. 2) 937ABC
第一题: A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputThe recent All-Berland Olympiad in Informatics featured n partic...
2018-02-26 12:20:27
304
原创 简单操作的位运算
///1.获得int型最大值int getMaxInt(){ return ( 1 << 31 ) - 1;///2147483647}///1.1另一种写法int getMaxInt1(){ return ~( 1 << 31 );}///1.2另一种写法int getMaxInt2(){ return ( 1 << -1 ) - 1;}///有些编译
2017-08-04 17:43:46
248
原创 DP最大公共子序列
第一题入门: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题意:求两个串的最长公共子序列 代码中的dp[i][j]表示0到i-1跟0到j-1的最长公共子序列 空间变化图如下: 分析如下: **1.**dp[i][j]=dp[i-1][j-1]+1;(a[i]==b[j]) (因为加和都是要和他前一项的基
2017-07-12 16:49:59
484
原创 HDU3047Zjnu Stadium(并查集)
In 12th Zhejiang College Students Games 2007, there was a new stadium built in Zhejiang Normal University. It was a modern stadium which could hold thousands of people. The audience Seats made a circle
2017-06-30 20:05:52
287
原创 HDU1663The Counting Problem
Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the lis
2017-06-27 09:49:46
489
原创 dfs 奇偶剪枝
什么是奇偶剪枝?把矩阵看成如下形式: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 从为 0 的格子走一步,必然走向为 1 的格子 。 从为 1 的格子走一步,必然走向为 0 的格子 。 即: 从 0 走向 1 必然是奇数步,从 0 走向 0 必然是偶数步。所以当遇到从 0 走向 0 但是要求时间是奇数的或者
2017-06-26 11:33:59
286
原创 810C. Do you want a date?
题目链接:http://codeforces.com/contest/810/problem/C题目大意: 告诉你一个含有n个互不相同的元素的集合,求它的所有非空子集中元素最大值与元素最小值之差的和。结果很大,输出它%1e9+7后的结果。推倒: 先对A排序,然后不妨枚举子集的最小元素,看一下它对答案的贡献考虑一个数列1 3 5 7 9,假设1是子集的最小元素再考虑集合的最大元素...
2017-06-05 11:18:11
366
原创 栈的应用---括号匹配
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAXLEN 5000typedef struct stack{ char base[100]; int top;} SqStack;SqStack *InitStack(){ SqStack *st; if(st=(SqSt
2017-04-11 16:34:47
258
原创 栈的应用 ---后缀表达式
后缀表达式定义:不包含括号,运算符放在两个运算对象的后面,所有的计算按运算符出现的顺序,严格从左向右进行(不再考虑运算符的优先规则,如:(2 + 1) * 3 , 即2 1 + 3 *举个例子:后缀表达式:9 3 1-3*+ 10 2/+后缀表达式规则:从左到右遍历表达式的每个数字和符号,遇到是数字就进栈,遇到是符号,就将处于栈顶两个数字出栈,进行运算,运算结果进栈,一直到最终获得结果。下面是详细的
2017-04-11 16:30:17
1892
原创 反转单链表的几种方法
反转单链表。假设单链表的数据结构定义如下:typedef struct LNode{ int data; struct LNode *next;}LNode, *LinkedList;第一种方法就是重新建立一个单链表newList,每次将list中的第一个结点放到newList后面。注释比较详细,所以就不具体说了,直接看代码吧:LinkedList ReverseS
2017-03-29 18:33:13
393
原创 2 进制转化8进制
10进制的28转化8进制为34编程实现#include<stdio.h>int main(){ int n; while(~scanf("%d",&n)) { int i,ok=0; for(i=27;i>=0;i-=3) { int num=n>>i; if(num)
2017-03-26 17:46:58
825
原创 判断一个数是否为2的次方幂
给定一个整数n,判断它是否为2的次方幂。思路:2,4,8,16,32….都是2的n次幂转换为二进制分别为: 10 100 1000 10000 100000这些数减1后与自身进行按位与,如果结果为0,表示这个数是2的n次幂 01 011 0111 01111 01111110&01 = 0 100&011 = 0 1000&0111 = 0
2017-03-26 17:40:35
757
原创 指针练习
有n个整数,使前面各数顺序向后移m个位置,最后m个数变成前面m个数,见图。写一函数:实现以上功能,在主函数中输入n个数和输出调整后的n个数。 Input 输入数据的个数n n个整数 移动的位置m Output 移动后的n个数 Sample Input 10 1 2 3 4 5 6 7 8 9 10 2 Sample Output 9 10 1 2 3 4 5 6 7 8 #inc
2017-03-14 09:44:07
302
原创 新世纪万年历
#include<stdio.h>#define Mon 1#define Tues 2#define Wed 3#define Thur 4#define Fri 5#define Sat 6#define Sun 0#define January_days 31#define February_days 28#define March_days
2017-03-01 23:21:11
270
原创 HDU1098 Ignatius's puzzle(数学归纳法求解)(数论)
Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find t
2017-02-27 17:35:05
413
原创 Student achievement management system
#include<stdio.h>#include<windows.h>#include<conio.h>#define SIZE 50struct Student{ char name[10]; //定义结构体 int ID; float Chinese; float Math; float English; float sum;
2017-02-16 11:23:10
561
原创 链表
链表是一种常见的重要的数据结构。它是动态地进行存储分配的一种结构。它可以根据需要开辟内存单元。链表有一个“头指针”变量,以head表示,它存放一个地址。该地址指向一个元素。链表中每一个元素称为“结点”,每个结点都应包括两个部分:一为用户需要用的实际数据,二为下一个结点的地址。因此,head指向第一个元素:第一个元素又指向第二个元素;……,直到最后一个元素,该元素不再指向其它元素,它称为“表尾”,它的
2017-02-04 18:17:56
299
原创 HDU1005
A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).Input The input consists of multiple te
2017-01-25 18:05:11
267
转载 0x12345678的内存形式
内存的存储的最小单元是一个字节,对于多字节存储的方式一般采用低位优先. #include <iostream> using namespace std; union { int a ; long b; unsigned char c; } m; int main(){ cout << siz
2017-01-24 20:40:30
5071
1
原创 GCD算法
欧几里德算法(Euclid)阐述了一种gcd算法。gcd/最大公约数/(greatest common divisor),简言之,我们想求gcd(x,y),假设(x>y),如果存在下式:x = q*y + r,那么则有gcd(x,y) = gcd(y,r) ,其实上式也称为gcd递归定理,即gcd(a,b) = gcd (b,a mod b)。 这个递归式看似很简单。实则它还是很值得推敲的,首
2017-01-22 23:14:01
4640
原创 sort函数的研究
一.实现原理原来,STL中的sort并非只是普通的快速排序,除了对普通的快速排序进行优化,它还结合了插入排序和堆排序。根据不同的数量级别以及不同情况,能自动选用合适的排序方法。当数据量较大时采用快速排序,分段递归。一旦分段后的数据量小于某个阀值,为避免递归调用带来过大的额外负荷,便会改用插入排序。而如果递归层次过深,有出现最坏情况的倾向,还会改用堆排序。 普通的快速排序 普通快速排序算法可以
2017-01-20 23:50:29
363
原创 贪吃的Flash
贪吃的Flash 描述 Flash学长去超市买好吃的,他到了超市发现超市的好吃的可真不少而且他每样都想吃,但是,他身上只有m元钱。那么问题来了,因为Flash学长很贪吃所以他想能买尽可能多的吃的,但是他没有足够的钱买下所有吃的,请帮助Flash学长设计一种方案使他可以买尽可能多的吃的。 输入 输入包含多组测试数据,每组测试数据第一行为两个整数n,m,表示共有n种吃的可供选择,Flash一
2017-01-19 14:39:53
323
原创 Universe7的神奇数
Universe7的神奇数 描述 Universe7从小喜欢奇特的东西,而且天生对数字特别敏感,一次偶然的机会,他发现了一个有趣的三位数145,这个数,它的各个位数的阶乘之和等于它本身。 啊哈,真是巧啊。Universe7非常喜欢这种数,由于他的发现,所以这里我们命名其为Universe7的神奇数。但是要判断这样的数还是有点麻烦啊,那么现在请你找出在当前范围内( [1, 21474836]
2017-01-18 21:54:41
479
原创 750B. New Year and North Pole
B. New Year and North Pole time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputIn this problem we assume the Earth to be a completely...
2016-12-31 11:03:02
337
1
原创 750A- New Year and Hurry
A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputLimak is going to participate in a contest on the last day o...
2016-12-31 09:14:32
346
原创 753 A. Santa Claus and Candies
A. Santa Claus and Candies time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputSanta Claus has n candies, he dreams to give them as gi...
2016-12-30 00:08:04
597
原创 递归
递归算法是一种直接或者间接调用自身函数或者方法的算法。Ja递归算法的实质是把问题分解成规模缩小的同类问题的子问题,然后递归调用方法来表示问题的解。递归算法对解决一大类问题很有效,它可以使算法简洁和易于理解。递归算法,其实说白了,就是程序的自身调用。它表现在一段程序中往往会遇到调用自身的那样一种coding策略,这样我们就可以利用大道至简的思想,把一个大的复杂的问题层层转换为一个小的和原问题相似的问题
2016-12-26 23:57:01
234
原创 小白理解的字符串
#include<stdio.h>#define N 12int main(){ char name[N]; printf("Enter your name:"); scanf("%s",name); printf("Hello %s!\n",name); return 0;}如下为运行结果: 那为什么会出现这种现象呢,原来scanf函数在读
2016-12-26 15:34:44
203
原创 A. Checking the Calendar
A. Checking the Calendar time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given names of two days of the week.Please, determin
2016-12-25 20:35:07
298
原创 677/AVanya and Fence
A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVanya and his friends are walking along the fence of height h and
2016-12-20 00:17:43
2298
原创 指针
我们区分一下这个1、int(*p)[3];——p为指向含3个元素的一维整形数组的指针变量(是指针) 2、int *p[3];——-定义指针数组p,该数组由3个指向整型数据的指针元素组成(是数组) 3、int(*)[3];——–实际上可以看作是一种数据类型。也就是第一个(int(*p)[3])中定义的p的数据类型 深入了解请看http://blog.youkuaiyun.com/touch_2011/art
2016-12-19 22:33:06
280
原创 A. Crazy Computer
A. Crazy Computer time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output ZS the Coder is coding on a crazy computer. If you don’t type in a word...
2016-12-17 14:25:57
506
原创 A. Buy a Shovel
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputPolycarp urgently needs a shovel! He comes to the shop and chooses...
2016-12-16 00:10:43
452
原创 C语言通过指针引用数组
输出数组中的全部元素(下标法):#include<stdio.h>int main(){ int a[10],i; for(i=0; i<10; i++) a[i]=i; for(i=0; i<10; i++) printf("a[%d]=%d\n",i,a[i]);} 输出数组中的全部元素(通过数组名计算元素的地址,找出元素的值):#i
2016-12-15 20:53:09
1227
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人