![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM刷题
文章平均质量分 60
JdiLfc
这个作者很懒,什么都没留下…
展开
-
E - Imprecise Computer Gym - 102920E-----递推+思维
题意:有一个不精确的计算机,只有当差值大于1的时候才能准确显示正确答案,其余的情况答案不唯一,例如:1>2也是有可能的,现在给出两次计算结果,根据两次计算结果判断D序列是不是符合题意的。题解:让误差尽量往后移动,例如当1位置对应的是1的时候,这个时候如果2位置对应的是0,说明3对2的影响也是有的,就把2对应位置的数字加1继续往后走,如果2位置对应的是1,说明这个影响是1造成的,就减1,变成0,即当前位置的值不会对之后的数字产生影响。即如果当前位置是1的话,后面的数要么加一要么减一,如果遍历到大于.原创 2021-02-19 08:45:37 · 334 阅读 · 0 评论 -
浮点二分--剪绳子,拯救王后
有N根绳子,第i根绳子长度为Li,现在需要M根等长的绳子,你可以对N根绳子进行任意裁剪(不能拼接),请你帮忙计算出这M根绳子最长的长度是多少。输入格式第一行包含2个正整数N、M,表示原始绳子的数量和需求绳子的数量。第二行包含N个整数,其中第 i 个整数Li表示第 i 根绳子的长度。输出格式输出一个数字,表示裁剪后最长的长度,保留两位小数。数据范围1≤N,M≤100000,0<Li<109输入样例:3 43 5 4输出样例:2.50样例解释第一根和第三根分别裁剪出一根原创 2021-01-27 15:29:03 · 169 阅读 · 0 评论 -
最长上升子序列问题求解
给定一个长度为N的数列(w[N]),求数值严格单调递增的子序列的长度最长是多少。样例输入格式第一行包含整数N。第二行包含N个整数,表示完整序列。输出格式输出一个整数,表示最大长度。数据范围1 ≤ N ≤ 1000,−1e9 ≤ 数列中的数 ≤ 1e9输入样例:73 1 2 1 8 5 6输出样例:4状态表示:f[i]表示从第一个数字开始算,以w[i]结尾的最大的上升序列。(以w[i]结尾的所有上升序列中属性为最大值的那一个)状态计算(集合划分):j∈(0,1,2,…,i-1原创 2021-01-27 15:02:24 · 280 阅读 · 1 评论 -
D - Monument Tour Gym - 102465D and 货舱选址----求某一个点到使其到所有点的连线之和最小问题
找出一条线,能把点连起来切最短,连接方式如图找出每个坐标的最小值和最大值,在这所有的点里面找到最中间的那个就是答案#include<bits/stdc++.h>using namespace std;int l[100100];int r[100100];int a[200100];int main(){ int n,m,k; cin>>n>>m>>k; memset(l,0x3f3f3f,sizeof(l)); .原创 2021-01-18 10:19:45 · 408 阅读 · 0 评论 -
区间操作--B - Blurred Pictures Gym - 102465B
Damon loves to take photos of the places he visits during his travels, to put them into frames. All of his photos are in a square format of N×N pixels. He brought back beautiful pictures of the many monuments in Paris, such as the Eiffel Tower or the Louvr原创 2021-01-18 09:25:07 · 386 阅读 · 0 评论 -
E - Rounding Gym - 102465E
You decided to stay an extra day in Paris visiting favorite places of Parisians around T’el’ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in surveys is less fun than coding. For this reason, you aske原创 2021-01-18 08:45:16 · 270 阅读 · 0 评论 -
A - Treehouses Kattis - treehouses--分块并查集
In a rainforest there are n treehouses high in the forest canopy on different trees (numbered from 1 to n). The i-th tree’s location is at (xi,yi). The first e of them in the list are close enough to neighboring open land around the rainforest so that tran原创 2020-12-27 12:33:31 · 384 阅读 · 0 评论 -
NIM博弈-Nim plus
Long Long and Mao Mao both have AKed the new div.1 round in Codeforces tonight, but it’s too early to sleep now. So they decide to play one special Nim game.In this special nim game, there are n paper balls on the table at the beginning of the game. But u原创 2020-12-21 21:29:01 · 215 阅读 · 0 评论 -
应用费马小定理快速求得大指数对p取模
费马小定理(Fermat’s little theorem)是数论中的一个重要定理,在1636年提出。如果p是一个质数,而整数a不是p的倍数,则有a^(p-1)≡1(mod p)。快速幂超时k = 998244353def fpow(a, b): ans = 1 while b > 0: if b % 2 == 1: ans = ans * a % k b //= 2 a = a * a % k原创 2020-12-13 23:03:49 · 490 阅读 · 0 评论 -
Can you answer these queries?(超时问题)--线段树
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon, it could原创 2020-12-07 19:56:27 · 222 阅读 · 0 评论 -
Manacher算法求回文串O(n)&&最长回文(例题)
参考:Manacher(马拉车)————O(n)回文子串HDU 3613 Best Reward(求前后缀回文 拓展KMP or Manacher)如果要求一个回文串:传(bao)统(li)算法就是:遍历每个字符,以该字符为中心向两边查找。时间复杂度为O(n^2);而对于Manacher算法可以将时间复杂度降为O(n);我们都知道,回文串有偶回文和奇回文之分,例如,abba,abcba,如果依照这种方法我们需要分情况讨论,现在我们对要处理的字符串处理一下,避免这种情况的讨论;对于字符串:abba原创 2020-12-05 21:08:38 · 168 阅读 · 0 评论 -
C - Cats
题意:有n个房子,你要把猫放进房子里,每个房子必须要放一个,猫的身高从1-20;猫有个毛病:身高相同的不能放一起,两个身高相同的之间的猫之间至少得有一只猫的身高比他们的身高小题解:找规律吧,比如说如果猫的身高为1的话就只能出现一次,2的话就只能出现两次,3只能出现四次(插空)…比如说:1只猫:12只猫可以这样:2 1 2之后就是:3 2 3 1 3 2 34 3 4 2 4 3 4 1 4 3 4 2 4 3 4…规律在while循环里面了:#include<bits/std..原创 2020-12-01 22:52:24 · 358 阅读 · 0 评论 -
求一段连续自然数的异或结果
求从n到m的异或结果:最坏时间复杂度为7次异或。例如:1到2 = 33到6 = 4#include<bits/stdc++.h>using namespace std;int yh(int n,int m){ if(abs(n-m)<4) { int n0=min(n,m); int n1,n2,n3; if(abs(n-m)<1) n1=0; else n1=n0+1; i原创 2020-11-30 21:13:55 · 347 阅读 · 0 评论 -
Strategic Game HDU - 1054--最小顶点覆盖
最小顶点覆盖!最小顶点覆盖 == 最大匹配(双向图)/2;要用邻接表,不然会超时!题目链接Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city,原创 2020-11-20 20:49:48 · 222 阅读 · 0 评论 -
Antenna Placement POJ - 3020--最少路径点覆盖问题
最少路径点覆盖=原图点个数-新图最大匹配数题目链接题目大意,给出一个图,图由" * " 或"o"组成,现在想要通过覆盖将全部的" * “变成"o”,覆盖规则:每次覆盖相邻的点,问最少需要多少个基站,能覆盖完全。本题主要是建图,图建完了,匈牙利算法求最大匹配就做完了;一种新的建图方式,因为直接建图的话,横纵坐标会出现相交的问题,建图错误,通过g将每个“*”编号,根据每一个编号进行建图;建出的图在代码后面;#include<iostream>#include<cstring&原创 2020-11-20 20:19:01 · 355 阅读 · 0 评论 -
Just a Hook HDU - 1698--线段树区间修改,lazy标记
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.Now Pudge wants to do some operations on the hook.Let us number the原创 2020-11-18 16:46:00 · 130 阅读 · 0 评论 -
汤圆の拯救计划-BFS(DFS会超时)
Description又到了汤圆星球一年一度的汤圆节了,但是大魔王却过来把汤圆公主抓走了Σ( ° △ °|||)︴身为汤圆骑士的QAQ蒟蒻自然而然的肩负着拯救汤圆的使命QAQ蒟蒻经历了千辛万苦(并没有)之后,来到了大魔王的城堡,根据情报,汤圆公主就被大魔王放在城堡内,然后QAQ蒟蒻发现自己是一个路痴,所幸的是他拿到了大魔王的城堡的地图,而且在这上面标注了自己和汤圆公主的位置,那么问题来了,聪明的你能帮他计算出需要多少单位的时间来赶到汤圆公主的位置吗?Ps:QAQ蒟蒻每一次都可以移动到相邻的非墙的原创 2020-09-28 22:34:47 · 159 阅读 · 0 评论 -
Divples .Gym - 102302B
这道题如果直接暴力一定会超时。这个时候可以利用sqrt缩减范围,然后求出另一部分,可以极大的简化代码运行时间。#include <bits/stdc++.h>using namespace std;long long x[2000001];int main(){ long long a,b; cin>>a>>b; int cnt=0; int t=sqrt(a); if(a%b==0) {原创 2020-09-26 22:54:36 · 83 阅读 · 0 评论 -
图的基本存储的基本方式四
图的基本存储的基本方式四Description解决图论问题,首先就要思考用什么样的方式存储图。但是小鑫却怎么也弄不明白如何存图才能有利于解决问题。你能帮他解决这个问题么?Input多组输入,到文件结尾。每一组第一行有一个数n表示n个点。接下来给出一个n*n的矩阵 表示一个由邻接矩阵方式存的图。矩阵a中的元素aij如果为0表示i不可直接到j,1表示可直接到达。之后有一个正整数q,表示询问次数。接下来q行每行有一个询问,输入两个数为a,b。注意:点的编号为0~n-1,2<=n<=5原创 2020-09-23 15:06:44 · 177 阅读 · 0 评论 -
数据结构实验之栈与队列二:一般算术表达式转换成后缀式
#include<iostream>#include<stdio.h>#include<string.h>#include<stack>using namespace std;int main(){ //a*b+(c-d/e)*f# char s[10000]; cin.getline(s,'#'); int len=strlen(s); stack<char>mystack; for(.原创 2020-09-19 21:15:51 · 61 阅读 · 0 评论 -
神,上帝以及老天爷(错排问题)
错位排列:第一步,错排第一号元素(将第一号元素排在k位置),有n-1种方法。第二步,错排其余n-1个元素。紧接第一步的结果,若第一号元素落在第k个位置,第二步就先把K排好1、 k 号元素排在第1个位置,留下的 n - 2 个元素在与它们的编号集相等的位置集上“错排”,有 f(n -2) 种方法;2、 k 号元素不排第 1 个位置,这时可将第 1 个位置“看成”第 k 个位置(也就是说本来准备放到k位置为元素,可以放到1位置中),于是形成(包括 k 号元素在内的) n - 1 个元素的“错排”,有 .转载 2020-09-19 19:55:56 · 110 阅读 · 0 评论 -
Daydreaming Stockbroker
#include<iostream>using namespace std;int main(){ long long a[10001]; int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; long long v=100; long long num=0; for(int i=0;i<n-1;i++) { if(a.原创 2020-09-17 22:10:07 · 90 阅读 · 0 评论 -
数据结构实验之串三:KMP应用
Description有n个小朋友,每个小朋友手里有一些糖块,现在这些小朋友排成一排,编号是由1到n。现在给出m个数,能不能唯一的确定一对值l和r(l <= r),使得这m个数刚好是第l个小朋友到第r个小朋友手里的糖块数?Input首先输入一个整数n,代表有n个小朋友。下一行输入n个数,分别代表每个小朋友手里糖的数量。之后再输入一个整数m,代表下面有m个数。下一行输入这m个数。Output如果能唯一的确定一对l,r的值,那么输出这两个值,否则输出-1SampleInput51 2原创 2020-10-11 10:16:36 · 99 阅读 · 0 评论 -
Coins HDU - 2844-完全背包
Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the原创 2020-10-10 19:38:54 · 146 阅读 · 0 评论 -
Number Sequence HDU - 1711
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2], ...... , a[K + M - 1] = b[M]. If there are.原创 2020-10-09 20:47:46 · 163 阅读 · 0 评论 -
饭卡 HDU - 2546
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。Input多组数据。对于每组数据:第一行为正整数n,表示菜的数量。n<=1000。第二行包括n个正整数,表示每种菜的价格。价格不超过50。第三行包括一个正整数.原创 2020-10-09 20:25:36 · 85 阅读 · 0 评论 -
Proud Merchants HDU - 3466
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.The merchants we.原创 2020-10-09 20:24:17 · 87 阅读 · 0 评论 -
Bone Collector-动态规划-背包问题
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …The bone collector had a big bag with a volume of V ,and along his trip of原创 2020-10-09 19:38:34 · 128 阅读 · 0 评论 -
数据结构实验之串一:KMP简单应用---strstr()函数的简单应用
数据结构实验之串一:KMP简单应用Description给定两个字符串string1和string2,判断string2是否为string1的子串。Input输入包含多组数据,每组测试数据包含两行,第一行代表string1(长度小于1000000),第二行代表string2(长度小于1000000),string1和string2中保证不出现空格。Output对于每组输入数据,若string2是string1的子串,则输出string2在string1中的位置,若不是,输出-1。Sample原创 2020-10-08 23:10:28 · 116 阅读 · 0 评论 -
C--最短路-二维数组会爆-Bellman-Ford 算法
C–最短路Description给出一个带权无向图,包含n个点,m条边。求出s,e的最短路。保证最短路存在。Input多组输入。对于每组数据。第一行输入n,m(1<= n && n<=510^5,1 <= m && m <= 310^6)。接下来m行,每行三个整数,u,v,w,表示u,v之间有一条权值为w(w >= 0)的边。最后输入s,e。Output对于每组数据输出一个整数代表答案。SampleInput3 11原创 2020-10-04 20:37:15 · 152 阅读 · 0 评论 -
顺序表应用8:最大子段和之动态规划法
Description给定n(1<=n<=100000)个整数(可能为负数)组成的序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的子段和的最大值。当所给的整数均为负数时定义子段和为0,依此定义,所求的最优值为: Max{0,a[i]+a[i+1]+…+a[j]},1<=i<=j<=n。 例如,当(a[1],a[2],a[3],a[4],a[5],a[6])=(-2,11,-4,13,-5,-2)时,最大子段和为20。注意:本题原创 2020-10-04 17:34:15 · 75 阅读 · 0 评论 -
Harmonic Number (II) LightOJ - 1245规律题
I was trying to solve problem ‘1234 - Harmonic Number’, I wrote the following code:long long H( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) res = res + n / i; return res;}Yes, my error was that I was using the inte原创 2020-10-24 21:31:12 · 149 阅读 · 0 评论 -
Harmonic Number LightOJ - 1234-调和级数求和
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:In this problem, you are given n, you have to find Hn.InputInput starts with an integer T (≤ 10000), denoting the number of test cases.Each case star原创 2020-10-24 20:55:11 · 279 阅读 · 1 评论 -
Goldbach`s Conjecture LightOJ - 1259 Runtime Error
Goldbach’s conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:Every even integer, greater than 2, can be expressed as the sum of two primes [1].Now your task is to check whether this conjecture holds f原创 2020-10-24 15:48:35 · 159 阅读 · 0 评论 -
A Simple Problem with Integers POJ - 3468
You have N integers, A1, A2, … , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.InputThe first line c原创 2020-10-23 22:20:14 · 115 阅读 · 0 评论 -
I Hate It HDU - 1754 (线段树)
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。学生ID编号分别从1编到N。第二行包含N个整数,代表这N个学生的初始成绩,原创 2020-10-23 20:27:08 · 92 阅读 · 0 评论 -
敌兵布阵 HDU - 1166(线段树)
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地原创 2020-10-23 19:03:35 · 131 阅读 · 0 评论 -
Shortest Prefixes POJ - 200(字典树)
A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that the empty string is not considered a prefix in this problem, but every non-empty str原创 2020-10-22 16:22:44 · 123 阅读 · 0 评论 -
Catch That Cow
DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has原创 2020-10-22 15:27:16 · 78 阅读 · 1 评论 -
数据结构实验之排序五:归并求逆序数
Description对于数列a1,a2,a3…中的任意两个数ai,aj (i < j),如果ai > aj,那么我们就说这两个数构成了一个逆序对;在一个数列中逆序对的总数称之为逆序数,如数列 1 6 3 7 2 4 9中,(6,4)是一个逆序对,同样还有(3,2),(7,4),(6,2),(6,3)等等,你的任务是对给定的数列求出数列的逆序数。Input输入数据N(N <= 100000)表示数列中元素的个数,随后输入N个正整数,数字间以空格间隔。Output输出逆序数。Sa原创 2020-10-22 15:01:25 · 254 阅读 · 0 评论