- 博客(45)
- 收藏
- 关注
原创 【模板】KMP
/*判断字符串b是否是a的字串*/#include<bits/stdc++.h>using namespace std;void GetNext(const char *p, int *next){ next[0] = -1; next[1] = 0; int j = 1; int k = 0; int lenp = strlen(p); while (j +...
2019-09-09 19:01:40 145
原创 【模板】中国剩余定理解同余方程(附_int128)
//问题:求解同余方程组// x ≡ a1 (mod b1)// x ≡ a2 (mod b2)// x ≡ a3 (mod b3)// ······// x ≡ an (mod bn)//其中b1,b2,b3,······ bn 为不一定两两互质的整数,求x的最小非负整数//模板#include<bits/stdc++.h>#define up(i, x, y)...
2019-09-09 18:46:53 417
原创 【模板】超级幂(欧拉降幂)
题意:求a ^ a ^ a ^ a…(b次)对mod取模#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long phi(long long x){ long long res=x; for(long long i=2;i*i&l...
2019-09-02 21:06:27 1722
原创 【模板】Floyd的优化
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int dp[105][105];int main(){ int n,m; scanf("%d%d",&n,&m); memset(dp,63,sizeof(dp));...
2019-08-24 17:08:39 350
原创 【模板】树状数组
POJ 3468题意:长度为n的序列,q次操作,C l,r,x表示区间 l~r 增加x,Q l,r表示求区间 l~r 的和。#include<iostream>#include<cstdio>#include<cstring>using namespace std;const long long maxn=1e6+10;long long a...
2019-08-14 17:28:47 104
原创 POJ 1182 食物链 (并查集)
Language:食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 105746 Accepted: 32016Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是...
2019-07-18 20:12:59 102
原创 POJ 3254 Corn Fields(状压DP)
DescriptionFarmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. R...
2019-05-22 20:43:23 171
原创 HDU - 5056 Boring count(尺取)
HDU - 5056You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.Inpu...
2019-03-11 21:22:27 119
原创 CodeForces - 1118F1 Tree Cutting (Easy Version) (树上dfs)
Tree Cutting (Easy Version)You are given an undirected tree of n vertices.Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at leas...
2019-03-06 19:14:48 244 1
原创 求组合数(扩展欧几里得+费马小定理)
扩展欧几里得:#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int mod=1e9+7;void exgcd(long long a,long long b,long long &x,long long &y){ if...
2019-02-27 20:22:44 298
原创 山东省第一届ACM大学生程序设计竞赛——Ivan comes again!(set+二分)
Problem DescriptionThe Fairy Ivan gave Saya three problems to solve (Problem F). After Saya finished the first problem (Problem H), here comes the second.This is the enhanced version of Problem H.T...
2019-02-26 21:29:43 257
原创 2019寒假训练赛10解题报告
A - Bungee Jumping POJ - 2463题意:有一个人要用一段绳子来跳楼,现在给你绳子的弹性系数、绳子的长度、楼的高度和人的质量,根据物理知识判断这个人是会摔死、还是安全着陆、还是被挂在半空(如果下落速度超过10m/s就会摔死、重力势能小于到达地面的弹性势能会被挂在半空中)。题解:初中物理重力势能:m * g * h弹性势能:0.5 * k * x ^ 2动能: 0.5...
2019-02-24 23:15:20 275
原创 2019寒假训练赛⑨解题报告
A - Minimum’s Revenge HDU - 5922题意:有n个节点,编号为1~n,任意两个点之间的权值为两点编号的最小公倍数,问建最小生成树的最少花费为多少。题解:最少花费即所有节点都与1号节点连边。答案为n*(n+1)/2-1C - Mr. Frog’s Problem HDU - 5924题意:给出两个数A和B,让你找出C和D满足A/B+B/A<=C/D+D/C,...
2019-02-22 13:50:10 140
原创 2019寒假训练赛08解题报告
B -Piggy-Bank HDU - 1114题意:给你存钱罐的重量和装满钱的存钱罐的重量,再给你一些货币的重量和价值,问这个存钱罐装满钱后的最小价值是多少。题解:完全背包问题。#include&amp;lt;iostream&amp;gt;#include&amp;lt;cstdio&amp;gt;#include&amp;lt;cstring&amp;gt;using namespace std
2019-02-18 16:39:03 169
原创 2019寒假训练赛07解题报告
A - Candy division Gym - 101597C题意:你有n块糖要分给三个小朋友,要求每个小朋友分到的数量可以被n整除,任意输出一种情况,如果不能则输出IMPOSSIBLE。题解:由题意,得出n=n/x+n/y+n/z,即1=1/x+1/y+1/z,满足此公式只有3 3 3或者2 4 4的组合。所以只要判断n能否被3或者4整除即可。#include&amp;lt;iostream...
2019-02-14 18:04:14 266
原创 2019寒假训练赛05解题报告
水体欢乐赛O(∩_∩)OA - Easy Marks SPOJ - EASYMRKS题意:你现在已经进行了n场考试并且知道了这n场考试的分数,现在你只剩下一场考试,问这场考试考多少分才能使得这n+1场考试的平均分为k。题解:k*(n+1)-sum。B - Candy I SPOJ - CANDY题意:有n个小朋友,每个小朋友都有一些糖,现在要糖多的小朋友分给糖少的小朋友一些糖使...
2019-02-12 14:33:42 179
原创 2019寒假训练赛04解题报告
米斯达镇楼A - Frog Jumping CodeForces - 1077A题意:有一只青蛙左右横跳,开始时青蛙在0位置,给你青蛙向右跳的距离a、向左跳的距离b和跳的步数k,问你青蛙最终的位置是多少。题解:简单模拟,如果k为奇数就输出 (a-b) * k / 2 + a,如果是偶数就输出(a-b) *k / 2。B - Disturbed People CodeForces - 1...
2019-02-10 15:52:04 335
原创 2019寒假训练赛03解题报告
这场比赛感觉。。。怎么说呢,WA、TLE、RE、MLE、PE、CE都有,做题十分钟,改BUG一小时(心情复杂)。A - Replace To Make Regular Bracket Sequence CodeForces - 612C题意:给你()、[]、{}、<>四种括号,任意左括号之间或者右括号之间都可以变换。现在给你一个括号组成的字符串,问使其中括号之间完全配对最少需要变...
2019-01-31 16:35:06 309
原创 2019寒假训练赛02解题报告
比完后等到12点成功一发呼符艾蕾get o( ̄▽ ̄)ブ(卡池刚开时70多石头都没出货…A - Partition CodeForces - 946A题意:给你一堆数,将其分成两部分,两部分分别求和再相减,使得差最大,求最大差。题解:非负数直接加,负数直接减,直接得到答案。B - A/B HDU - 1576题意:要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(...
2019-01-30 13:49:17 180
原创 2019寒假训练赛01解题报告
起床发现8点50多了,想起来还有个比赛,吃了点饭开始准备,从9点打到11点A了6道题,看其他的题没啥思路就去干别的事了,最后一个小时回来专心做F题,思路没错但还是没做出来,其他三个都是考验脑力的,果然我太菜了。A - The kth great number HDU-4006题意:输入n和k,以下n行,每行第一个字符为I,后面将一个数字加入序列中,如果为Q,则输出当前序列第k大的数。题解:用...
2019-01-24 22:29:45 263 1
原创 判断素数
问题:给你一个数,问你这个数是否为素数?定理:如果一个数不能被其平方根以内的(素)数整除,其一定为素数。证明:对于一个合数n,其一定可以达成n=a*b的形式(a和b为n的约数),其中一个约数大于等于n\sqrt{n}n ,另一个小于等于n\sqrt{n}n,所以如果n不能被n\sqrt{n}n以内的(素)数整除,其必为素数。普通版:#include&lt;iostream&gt;...
2018-12-14 21:12:27 355
原创 ZOJ 4062 Plants vs. Zombies(二分)
ZOJ 4062 Plants vs. Zombies意义不明的花妈和芳香。There are plants in DreamGrid’s garden arranged in a line. From west to east, the plants are numbered from 1 to n and the -th plant lies meters to the eas...
2018-12-08 16:38:58 397
原创 HDU 5532 Almost Sorted Array(最长不上升||不下降子序列)
Problem DescriptionWe are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algor...
2018-12-01 22:02:07 173
原创 HDU 4422 The Little Girl who Picks Mushrooms
HDU 4422 The Little Girl who Picks Mushrooms题意:在幻想乡的一天,爱丽丝准备去五座山上去采蘑菇。她带了五个袋子,每到一座山,她就用一个袋子来装蘑菇。爱丽丝想尽可能多地带蘑菇回家做美味的蘑菇汤。不过爱丽丝居住的魔法森林有三个妖精——桑尼、露娜和斯塔,爱丽丝必须给她们三袋子蘑菇,这些蘑菇总数必须为整数千克。Sample Input194512 5...
2018-11-30 21:38:15 239
原创 QLU ACM新生赛 约数个数&&折纸达人
题目描述pq表示p的q次方,正整数M可以分解为M=(p1a1)(p2a2)*(p3a3)……(pnan)的形式,其中p1,p2……pn为质数(大于1并且只能被1和自身整除的数叫做质数)。a1,a2……an为整数。例如18=(21)(32),45=(32)*(5^1)。给出n和一个质数g,以及正整数M分解后的形式,求M的所有约数中,有多少能被g整除。输入第一行 两个数 n和g。 0&amp;lt;n...
2018-11-28 19:36:07 265
原创 HDU 4725 The Shortest Path in Nya Graph(SPFA)
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just ...
2018-11-24 16:01:29 125
原创 POJ 3159 Candies(差分约束)
POJ 3159 CandiesDescriptionDuring the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flym...
2018-11-19 20:06:46 130
原创 POJ 1860 Currency Exchange(spfa)
POJ 1860 Currency ExchangeDescriptionSeveral currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operation...
2018-11-14 20:46:37 276
原创 LightOJ - 1074 Extended Traffic(spfa+判负环)
Dhaka city is getting crowded and noisy day by day. Certain roads always remain blocked in congestion. In order to convince people avoid shortest routes, and hence the crowded roads, to reach destinat...
2018-11-14 19:58:45 262
原创 POJ 3268 Silver Cow Party(spfa)
Silver Cow PartyLanguage:Silver Cow PartyTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 30402 Accepted: 13798DescriptionOne cow from each of N farms (1 ≤ N ≤ 1000) conveniently numb...
2018-11-14 18:35:23 205
原创 分解质因数
给你一个数n(2&amp;lt;=n&amp;lt;=1000000),求n的质因数。欧拉筛法(O(n)):素数的倍数一定为合数,我们每找到一个数,就将其素数倍数的数标记为合数。#include&amp;lt;iostream&amp;gt;#include&amp;lt;cstdio&amp;gt;#include&amp;lt;cstring&amp;gt;using
2018-11-09 21:28:37 747
原创 单链表的基本操作
单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数据元素。链表中的数据是以结点来表示的,每个结点的构成:元素(数据元素的映象) + 指针(指示后继元素存储位置),元素就是存储数据的存储单元,指针就是连接每个结点的地址数据。#include<iostream>#include<cstdio>#include<cstdlib>using...
2018-11-07 20:33:58 826 3
原创 POJ 1797 Heavy Transportation(二分+宽搜)
DescriptionBackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the pl...
2018-11-03 19:34:08 169
原创 POJ 2253 Frogger(二分+宽搜)
DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of t...
2018-11-02 19:31:18 172
原创 POJ 2387 Til the Cows Come Home(SPFA||Dijkstra)
POJ 2387 Til the Cows Come HomeDescriptionBessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie n...
2018-10-31 20:38:52 175
原创 HDU - 2612 Find a way(宽搜)
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.Yifenfei’s home is at the cou...
2018-10-26 19:59:59 114
原创 POJ 3414 Pots(宽搜)
DescriptionYou are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) em...
2018-10-24 20:27:23 137
原创 UVA-11624 Fire!(宽搜)
UVA-11624 Fire!Joe works in a maze. Unfortunately, portions of the maze havecaught on fire, and the owner of the maze neglected to create a fireescape plan. Help Joe escape the maze.Given Joe’s lo...
2018-10-22 21:21:27 214
原创 POJ 3279 Fliptile(枚举+模拟)
DescriptionFarmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15...
2018-10-14 23:15:15 200
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人