![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM & 算法
weixin_40799464
这个作者很懒,什么都没留下…
展开
-
The 2018 ACM-ICPC Chinese Collegiate Programming Contest B. Rolling The Polygon
通过这个题知道了余弦定理的使用。cos A=(b*b+c*c-a*a)/(2*b*c); 之后通过acos(cos A)就可以得出弧度来了。弧度乘以半径就是轨距。再把多个轨迹相加就得出答案了。ac代码:#include <iostream>#include <cmath>using namespace std;const double PI=acos...原创 2018-07-18 11:48:09 · 245 阅读 · 0 评论 -
烽火传递(dp+单调队列)
烽火台又称烽燧,是重要的军事防御设施,一般建在险要或交通要道上。一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息;夜晚燃烧干柴,以火光传递军情,在某两座城市之间有 n 个烽火台,每个烽火台发出信号都有一定代价。为了使情报准确地传递,在连续 m 个烽火台中至少要有一个发出信号。请计算总共最少花费多少代价,才能使敌军来袭之时,情报能在这两座城市之间准确传递。 Input第一行:两个整数 N,M...原创 2018-10-23 11:41:58 · 721 阅读 · 0 评论 -
算个欧拉函数给大家助助兴(米勒拉宾(判断素数)+Pollard_rho(求一个大数的因子 ))
这篇博客讲的很好:https://www.cnblogs.com/ZERO-/p/9302169.html题目描述木南有一天学习了欧拉函数,知道了对正整数n,欧拉函数是小于n的正整数中与n互质的数的数目。那么他定义f(n)为有多少个小于等于n的数可以整除n。例如f(4)=3。(可以被1,2,4整除)。那么你可以写个程序计算一下f(n)吗?输入输入一个n n≤1018n...转载 2018-10-26 10:42:29 · 215 阅读 · 0 评论 -
海港
题目链接:http://210.44.144.221/problem.php?cid=1002&pid=0按照人数来入队,如果按照船来入队的话会超时,他还很是明确的提醒了∑ki≤3∗105:所以如果按照船来储存不行的话,那就通过人头来储存吧:代码: #include <iostream>#include <cstring>#include &l...原创 2018-10-30 22:41:52 · 153 阅读 · 0 评论 -
求和
题目链接:https://www.luogu.org/problemnew/show/P2671通过分解因式总结规律。可以得到公式如下:同为奇数偶数的n个同颜色的格子的公式为:(i1+i2+.....in)(num[1]+num[2]....num[n])+(n-2)( i1*num[1]+i2*num[2]......in*num[n] ).其中i代表的是第几个,num[i]...原创 2018-11-06 12:09:57 · 143 阅读 · 1 评论 -
Books
如果书中有价格有零的,那么零都要加上。之后m=m-零的个数,之后选取前m本非零的书籍加到sum上,最后从剩下的书籍中选择价格最小的书籍加到sum上,最后sum-1就行了。要注意如果n==m,直接输出richman。代码:#include <iostream>#include <stdio.h>#include <algorithm>using n...原创 2018-11-13 11:38:01 · 174 阅读 · 0 评论 -
跳房子
链接:https://www.luogu.org/problemnew/show/P3957动态规划,单调队列+二分。//my.cpp.#include <iostream>#include <stdio.h>#include <cstring>using namespace std;/*定义dp[i]是跳到了第i个位置之后的最大得分。...原创 2018-11-08 22:57:48 · 635 阅读 · 0 评论 -
noip 2017棋盘
题目链接:https://www.luogu.org/problemnew/show/P3956这个题只要注意一下深度优先搜索或者是宽度优先搜索剪支就行了。纯粹的暴力搜索是不行的,还要注意一下只有一个空格的时候是恒为零的就行了。以下代码是宽度优先搜索:#include <iostream>#include <stdio.h>#include <c...原创 2018-11-22 23:10:55 · 369 阅读 · 0 评论 -
2013NOIP普级组-- 小朋友的数字
题目链接:https://www.luogu.org/problemnew/show/P1982 很显然,这是一个最大字段和问题,但是要注意的是在算每个小朋友的分数的时候是会爆longlong的,我们注意到小朋友的特征值和分数是递增的,手动进行模拟特征值和分数可以得出: 如果要求的小朋友的分数的上一个小朋友的特征值是大于等于零的,那么往后的时候每一个小朋友的分数都...原创 2018-11-20 10:23:58 · 377 阅读 · 0 评论 -
Traveling on the Axis (The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054题意就是一个小孩走一段路,这条路上有n个红绿灯,并且告诉了你初始红绿灯的状态,用1表示路灯,0表示红灯,并且没经过一秒红绿灯就转换,从绿灯变为红灯或是从红灯变为绿灯。小孩走这一段路,如果碰到了绿灯直接走过去,如果碰到了红灯停一秒钟等红灯变为绿灯在走过去...原创 2018-11-20 11:42:47 · 133 阅读 · 0 评论 -
NOIP 2014 联合权值
题目链接:https://www.luogu.org/problemnew/show/P1351参考洛谷题解:使用链式前向星储存图。如果使用深度优先搜索的话,是会超时的,如果遍历中间的点,虽然比直接遍历快一点,但是也会超时,画一个有三个顶点一个中心的菊花图,题目就是要求三个顶点两两相乘的和,找规律可得到:结果为三个顶点的和的平方减去三个顶点的平方和,推广到n个顶点也是一样的。由此得出代...原创 2018-11-20 12:35:36 · 167 阅读 · 0 评论 -
小米全国高校编程大赛 高弗雷勋爵
题目链接:https://code.mi.com/problem/list/view?id=113&cid=2小米oj给定了输入格式,所以要完全按照他的来,输入字符之后在转换为数字就行了。这道题注意到数据的大小为1e9,所以直接暴力肯定是会超时的,所以首先排序,之后定义一个累加器,看看前边的数字减为小于等于零时一共减少了个二,然后根据累加器来计算当前数字的值。一直计算到所有的数...原创 2018-11-29 10:58:56 · 769 阅读 · 1 评论 -
约数个数 (排列组合中的乘法原理)
问题 A: 约数个数时间限制: 2 Sec 内存限制: 128 MB提交: 313 解决: 39提交 状态 讨论版命题人:admin题目描述p^q表示p的q次方,正整数M可以分解为M=(p1^a1)*(p2^a2)*(p3^a3)*……*(pn^an)的形式,其中p1,p2……pn为质数(大于1并且只能被1和自身整除的数叫做质数)。a1,a2……an为整数。例如18=(2^1...原创 2018-11-29 11:44:22 · 1538 阅读 · 0 评论 -
线段树递归和非递归实现+hdu1166 敌兵布阵
递归代码:#include <string>#include <cstring>#include <iostream>#include <stdio.h>using namespace std;const int inf=1e5+7; //最多的数量。int sum[inf<<2],add[inf<&...原创 2018-09-22 18:42:54 · 295 阅读 · 0 评论 -
H. Fight Against Monsters
题目链接贪心求解,a.atk/a.time值较大的排在前边。但是这样使用除法会导致精度损失,compare函数中的比较规则变为a.atk*b.time>b.atk*a.time就行了。当相等的时候按照atk的大小进行排序就行。(原先的时候想按照a.atk/a.hp值较大的排在前边,想了一下是不行的。因为hp不同的怪兽攻击的次数可能是一样的。)代码:#include <i...原创 2018-10-14 17:47:14 · 628 阅读 · 0 评论 -
2018百度之星度度熊学队列
使用stl中的list就可以了,不知道为啥用reverse会wa,只能是一个个的插入list了,索幸没有超时。代码:#include <iostream>#include <list> #include <algorithm>using namespace std; const int inf=150000+7;list<i...原创 2018-10-12 17:53:44 · 84 阅读 · 0 评论 -
2018 青岛网络赛C题Halting Problem
判断一个指定的程序是一直运行下去还是会停止。停止好判断,就是如何判断是否会一直运行下去。当第二次到达第n步的时候,如果此时的r仍然是第一次到达第n步时候的r,那么这个程序会一直运行下去。通过这道题还知道了对bool类型的数组处理是比对int类型的数组处理快的。全局变量是比局部变量可以申请的内存多的。代码:#include <iostream>#include <cs...原创 2018-09-22 12:05:22 · 169 阅读 · 0 评论 -
二维前缀和。
二维前缀和就是求一个矩形内指定矩形区域中的和。利用简单的容斥原理可以很容易的推导出来。代码如下:#include <iostream> //简单的容斥原理。 using namespace std; //二维前缀和。 const int inf=105;int a[inf][inf];int jx[inf][inf];int main(){ ...原创 2018-08-09 10:43:34 · 581 阅读 · 0 评论 -
Restoring Road Network(弗洛伊德算法的使用)
Restoring Road Network(中石油6610)弗洛伊德算法的使用。代码: #include <iostream>using namespace std;const int N=305;int arr[N][N];const int inf=1e9+10;int main(){ int n; while(cin>>...原创 2018-08-06 13:07:04 · 177 阅读 · 0 评论 -
Coloring Dominoes
题目描述We have a board with a 2×N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1×2 or 2×1 square.Then, Snuke decided to paint these dominoes using three c...原创 2018-08-10 22:15:25 · 99 阅读 · 0 评论 -
Snuke Festival(二分法)
题目描述The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each o...原创 2018-08-08 23:25:57 · 177 阅读 · 0 评论 -
Find Integer(费马大定理的使用)
Problem Description people in USSS love math very much, and there is a famous math problem . give you two integers n ,a ,you are required to find 2 integers b ,c such that an +bn=cn . ...原创 2018-08-27 09:15:53 · 143 阅读 · 0 评论 -
Down the Pyramid
Do you like number pyramids? Given a number sequence that represents the base, you are usually supposed to build the rest of the "pyramid" bottom-up: For each pair of adjacent numbers, you would compu...原创 2018-08-27 21:59:42 · 346 阅读 · 0 评论 -
Skyscraper
题目描述Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, beca...原创 2018-08-24 23:30:18 · 594 阅读 · 0 评论 -
J题:Sum
题目链接:https://nanti.jisuanke.com/t/30999代码:线性筛找出最小的素数来,之后递推找规律求解。 #include <iostream>#include <cstring>using namespace std;const int inf=2e7+10; int flag[inf+10],ans[inf+...翻译 2018-09-05 20:20:45 · 129 阅读 · 0 评论 -
Four-tuples (2018山东省省赛 容斥定理)
感谢大佬的博客:https://blog.csdn.net/qq_41021816/article/details/80328475开始的时候不知道如何求满足性质pi的元素个数,知道参考了上面的大佬的博客才明白。还有就是要知道这中取模的,如果ans要减的话,在减之后必须要加上mod在取模才行。代码:#include <iostream> using nam...原创 2018-09-15 19:08:31 · 173 阅读 · 0 评论 -
2018南京网络赛 G. Lpl and Energy-saving Lamps (线段树非递归实现)
线段树非递归实现。点修改下的区间查询。注意预处理的时候要把一到十万的都进行处理一遍,因为输入的月份不一定在月份的个数之内。 #include <iostream>#include <cstring>using namespace std;const int inf=1e5+7;const int themax=2e9+10;int arr[4*inf]...原创 2018-09-18 12:40:20 · 106 阅读 · 0 评论 -
2018南京网络赛L题 Magical Girl Haze(分层图+优先队列优化的dijkstra)
使用优先队列优化过的dijkstra时间复杂度可以达到O(v*logn),还是很快的。#include <iostream> //最好是用long long 类型的。 #include <cstring>#include <queue> using namespace std;typedef long long ll;...原创 2018-09-13 17:20:50 · 152 阅读 · 0 评论 -
2018山东省省赛 问题 H: Dominoes
广度优先搜索。注意题目中说结果可能很大,但是实际上是到不了1e9+9的,有些题目就是故意吓唬人。代码:#include <iostream> //分开也是可以的吧。 #include <queue>#include <cstring>using namespace std;typedef long long ll;int map[11][1...原创 2018-09-19 12:24:23 · 151 阅读 · 0 评论 -
智慧的邓布利多
哈利与邓布利在寻找魂器的过程中,被困在了魔法阵中,这个魔法阵由n个石板构成,石板从小到大排成一列。邓布利多仔细观察着些石板,发现,每个石板可以近似的看成腰长为XnX_nXn厘米的等腰直角三角形(Xn=1,2,3,4,…n X_n=1,2,3,4,…n Xn=1,2,3,4,…n)。这时,邓布利多对哈利说:“试试将石板放在坐标系中吧”(放置方法固定,见样例),哈利于是将石板放在了坐标...原创 2018-12-21 10:46:08 · 196 阅读 · 0 评论