
算法
文章平均质量分 50
QEcode
这个作者很懒,什么都没留下…
展开
-
广师oj 2237 - 第k小的数
有n个数,请你找出第k小的数。输入描述 第一行有2个正整数n,k(n,k<=10^6) 第二行有n个非负数ai(ai<=10^5)输出描述 输出第k小的数。样本输入5 2 1 5 3 4 5样本输出 3快排后直接找第k小的数#include <stdio.h>#include <algorithm>using namespace std;int a[100005];int main()原创 2017-07-08 17:06:34 · 587 阅读 · 0 评论 -
Exams
Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m.About every day we know exam for which one of m subjects can be passed o原创 2017-11-14 19:25:50 · 433 阅读 · 0 评论 -
Pavel and barbecue
Pavel and barbecue time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pavel cooks barbecue. There are n skewers, they lay on a brazie原创 2017-11-28 23:01:59 · 356 阅读 · 0 评论 -
Anton and Fairy Tale
Anton likes to listen to fairy tales, especially when Danik, Anton’s best friend, tells them. Right now Danik tells Anton a fairy tale:“Once upon a time, there lived an emperor. He was very rich and ha原创 2017-11-15 21:38:14 · 350 阅读 · 0 评论 -
Triangle
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coord原创 2017-11-22 21:25:24 · 387 阅读 · 0 评论 -
欧拉线性筛法求素数
我们先来看一下最经典的埃拉特斯特尼筛法。时间复杂度为O(n loglog n)[cpp] view plain copy print?int ans[MAXN]; void Prime(int n) { int cnt=0; memset(prime,1,sizeof(prime)); prime[0]=prime[1]=0; for(int i=2;i<转载 2017-11-21 11:57:45 · 579 阅读 · 0 评论 -
2017网络新生赛题解
硬币翻转 题目描述在桌面上有一排硬币,共N枚,每一枚硬币均为正面朝上。现在要把所有的硬币翻转成反面朝上,规则是每次可翻转任意N-1枚硬币(正面向上的被翻转为反面向上,反之亦然)。求一个最短的操作序列(将每次翻转N-1枚硬币成为一次操作)。输入输出格式输入格式: 输入只有一行,包含一个自然数N(N为不大于100的偶数)。输出格式: 输出文件的第一行包含一个整数S,表示最少需要的操作次数。接下来的原创 2017-11-13 22:57:34 · 1550 阅读 · 0 评论 -
2018-新生
A. I Speak WhalesProblem Description According to Wikipedia, a Walsh matrix is a specific square matrix, with dimensions equal to a power of 2, the entries of which are +1 or -1, and the property t...原创 2018-05-13 10:11:03 · 437 阅读 · 0 评论 -
2018-非新生
A. Fire NetProblem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. ...原创 2018-05-13 11:08:31 · 530 阅读 · 0 评论 -
Mafia
One day n friends gathered together to play “Mafia”. During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many r原创 2017-11-13 22:41:24 · 730 阅读 · 0 评论 -
筛选法求素数
筛选法求素数转载 2017-10-14 13:57:22 · 686 阅读 · 1 评论 -
广师oj 2236-孤独数
## 广师oj 2236-孤独数 ##有2n+1个数,其中有n对数字是成双出现的,有且仅有1个数字只有它自己一个。请你找出这个孤单数。第一行有且只有一个正整数n(n<=500000) 第二行有2n+1个数ai(-10^9<=ai<=10^9)有且只有一个数,输出这个孤单数。36 2 6 3 7 7 32利用异或^,偶数个相同的数字异或之后为零,任何非零数与零异或为其本身。#includ原创 2017-07-06 16:24:00 · 1215 阅读 · 0 评论 -
广师oj 2238 最长回文子串
回文串,就是从前往后和从后往前看都是一样的字符串。那么现在给你一个字符串,请你找出该字符串中,长度最大的一个回文子串。输入描述 有且仅有一个仅包含小写字母的字符串,保证其长度不超过5000输出描述 有且仅有一个正整数,表示最长回文子串的长度样本输入abccbxyz 样本输出 4将每个字符都当作回文串的中心,一这个字母为中心向两边比较 但要考虑两种情况:aba型,abba型;#include原创 2017-07-08 19:25:37 · 546 阅读 · 0 评论 -
KMP算法
KMP算法原创 2017-10-11 21:22:39 · 204 阅读 · 0 评论 -
广师oj1018-麦森数(快速幂+高精度乘法)
快速幂算法原创 2017-10-11 19:13:40 · 342 阅读 · 0 评论 -
快速求幂算法
快速求正整数次幂原创 2017-10-11 18:35:42 · 445 阅读 · 0 评论 -
广师oj-1017 栈
题目描述 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表。栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈)。栈的重要性不言自明,任何一门数据结构的课程都会介绍栈。宁宁同学在复习栈的基本概念时,想到了一个书上没有讲过的问题,而他自己无法给出答案,所以需要你的帮忙。宁宁考虑的是这样一个问题:一个操作数序列,从1,2,一直到n(图示为1到3原创 2017-10-11 15:10:06 · 436 阅读 · 0 评论 -
栈-八皇后问题
八皇后问题原创 2017-10-12 10:06:15 · 1501 阅读 · 0 评论 -
数列排序
题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格式: 第一行,正整数n (n<=100,000)。 以下若干行,一共n个数,用空格分隔开,表示数列{an},任意-231//使用快排和二分查找模拟选择 #include <cstdio>#include <algo原创 2017-10-14 11:59:43 · 1480 阅读 · 0 评论 -
哈希表(散列表)
一,什么是哈希表由于哈希表一般用数组和链表实现,所以先了解一下数组和链表的基本特征:数组:采用一段连续的存储单元来存储数据。 对于指定下标的查找,时间复杂度为O(1), 因为对于数组来说,第n个下标的地址为 数组首地址+n*数组元素的存储空间,所以查找指定下标的数据,可以通过一次计算获取; 通过给...原创 2018-10-18 14:18:20 · 308 阅读 · 0 评论