
ACM
coderyzh
这个作者很懒,什么都没留下…
展开
-
欧拉函数
A - 欧拉函数对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目。此函数以其首名研究者欧拉命名,它又称为Euler's totient function、φ函数、欧拉商数等。例如:φ(8) = 4(Phi(8) = 4),因为1,3,5,7均和8互质。Input输入一个数N。(2 <= N <= 10^9)Output输出Phi(n)。Sample Input8Sample ...原创 2018-06-14 20:37:17 · 397 阅读 · 0 评论 -
UVa 11401 Triangle Counting (递推)
题目传送门题意:给你一个n,问你1~n中取出3个数构成不同三角形的种类数,但是n<3时就弹出噢,刚开始就因为这个WA了。题解:找规律,直接看表格。#include<iostream>using namespace std;const int maxn=1e6+7;long long f[maxn];int main(){ f[4]=1,f[...原创 2018-11-10 15:28:32 · 191 阅读 · 0 评论 -
UVa 11806 Cheerleaders(容斥+组合数学)
题目传送门题意:在n*m(n行m列)的棋盘里放石头,第一行,第一列,最后一行,最后一列至少要有一个石头,所给的k个石头必须要全部用完,问:有放石头的方式的种类数。题解:容斥原理,如果把石头全部放进去种类数就是C(n*m,k);所以题目所求的就是全部放进去的种类数减去不满足条件的种类数;全集S=C(n*m, k) A表示第一行不放的方案集合B表示最后一行不放的方案集合...原创 2018-11-11 15:18:29 · 181 阅读 · 0 评论 -
POJ 2392 Space Elevator(多重背包)
题目传送门DescriptionThe cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks w...原创 2018-11-05 12:46:53 · 304 阅读 · 0 评论 -
POJ 3181 Dollar Dayz(动态规划+大数)
题目传送门DescriptionFarmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Far...原创 2018-11-05 17:20:21 · 200 阅读 · 1 评论 -
NEERC2005,LA 3516 Exploring Pyramids
题目传送门题意:给一颗多叉树,每个结点的子结点都有从左到右的顺序,从根结点开始,每次尽量选择靠左的分支走,走不通就回溯,把遇到的字母记录下来,可以得到一个序列。 给定一个序列,问有多少树和他对应?题解:显然,遍历一遍字符串,字符串要形成树,首位一定要相同,每棵树有很多个分支,每个分支最终都会返回该分支所对应的分节点。d[i][j] 表示字符区间 [i,j] 对应的不同的树的数目...原创 2018-11-11 15:48:02 · 155 阅读 · 0 评论 -
UVa 11361 Investigating Div-Sum Property
题目传送门题意:输入A,B,K,问A~B之间存在多少个数满足下列条件:该数为K的倍数,并且各位数之和也是K的倍数。题解:点击大神题解一,讲的很详细 大神题解二,讲的也很详细#include <iostream>#include <algorithm>#include <cstdio>#include <cstring&...原创 2018-11-11 16:14:38 · 166 阅读 · 0 评论 -
CodeForces 1075B Taxi drivers and Lyft
题目传送门Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.Lyft has become so popular so that it is now used by all mm taxi drivers...原创 2018-11-11 16:49:33 · 470 阅读 · 0 评论 -
POJ 3104 Drying(二分+计数)
题目传送门It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faste...原创 2018-11-11 17:31:05 · 170 阅读 · 0 评论 -
UVa 11889 Benefit (枚举因子)
题目传送门题意:输入一个T代表多组数据,输入A,C分别为LCM(A,B)=C,求所对应的最小的B,并且输出,否则输出“NO SOLUTION”;题解:怎么想???刚开始想的是两个数直接除,显然是不行的,例如LCM(1,12)=12,LCM(2,12)=12,所以直接用C/A肯定是错误的;还是乖乖一个一个遍历吧。将C一个一个分解,换来的却是TLE!#include <iost...原创 2018-11-16 11:01:34 · 128 阅读 · 0 评论 -
UVa 10943 How do you add?
题目传送门题意:求将数字n分为k个数之和的种类数。高中排列组合的题目,隔板法!题解:为啥要写这个题解,因为WA了很多次。可以把一个数字n,看成是n个球,然后用k个隔板把他分开就行。所以C[n+1][k-1],然后就WA了#include <iostream>//错误代码#include <algorithm>#include <cstdio>...原创 2018-11-17 13:21:03 · 173 阅读 · 0 评论 -
UVa 10780 Again Prime? No Time.(因子分解)
题目传送门题意:输入包含多组数据,输入的m,n。n!%m^k==0,求最大的这个k。题解:对n,m进行因子分解,记录每个质因子出现的次数,m的所有质因子出现的次数中的最小次数就是答案。#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>...原创 2018-11-17 17:43:04 · 191 阅读 · 0 评论 -
UVa 10892 LCM Cardinality (质因数分解)
题目传送门题意:输入一个数n,问若n==LCM(a,b),存在的这种(a,b)共有多少对。题解:首先先了解一下LCM(a,b)的由来。将a,b拆分设max(kai,kbi)=ri;所以如果a中取ri,则b只能取[0,ri-1],则有ri种;如果b中取ri,则a只能取[0,ri-1],则有ri种;如果a,b均取ri,则有1种;所以对于每个因子pi均有2*ri+...原创 2018-11-17 19:00:52 · 170 阅读 · 0 评论 -
UVa 227 Puzzle(模拟+字符串操作)
题目传送门 题意:有一个5*5的网格,其中恰好有一个格子是空的,其他格子各有一个字母。一共有4种指令:A,B,L,R,分别表示把空格上,下,左,右的相邻字母移到空格中。输入初始网格和指令序列(以数字0结束),输出指令执行完毕后的网格。如果有非法指令,应输出“This puzzle has no final configuration.”题解:模拟一下就出结果了,处理输入输出比较麻烦。用了g...原创 2018-12-03 21:30:38 · 149 阅读 · 0 评论 -
UVa 11538 Chess Queen(计数问题)
题目传送门 题意:给你一个n*m(n行m列)的棋盘,棋盘里有两个黑白旗子,当黑白旗子在同一行,同一列,同一对角线时处于攻击状态,问处于攻击状态时的种类数。题解:根据题意可以将种类数分为三种类型:一、当两种棋子处于同一列的情况:ans1=m*(m-1)*n;二、当两种棋子处于同一行的情况:ans2=n*(n-1)*m;三、当两种旗子处于对角线的情况: ...原创 2018-11-10 10:49:13 · 210 阅读 · 0 评论 -
POJ 3046 Ant Counting(多重集组合数)
题目链接:http://poj.org/problem?id=3046DescriptionBessie was poking around the ant hill one day watching the ants march to and fro while gathering food. She realized that many of the ants were sibling...原创 2018-11-02 19:06:56 · 226 阅读 · 0 评论 -
POJ 3616 Milking Time
题目链接:http://poj.org/problem?id=3616 Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1...原创 2018-10-30 21:33:44 · 122 阅读 · 0 评论 -
51Nod 1179 最大的最大公约数
1179 最大的最大公约数题目来源: SGU基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注给出N个正整数,找出N个数两两之间最大公约数的最大值。例如:N = 4,4个数为:9 15 25 16,两两之间最大公约数的最大值是15同25的最大公约数5。Input第1行:一个数N,表示输入正整数的数量。(2 <= N &...原创 2018-09-19 12:48:54 · 132 阅读 · 0 评论 -
51Nod 1019 逆序数(离散化+树状数组)
1019 逆序数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序数。如2 4 3 1中,2 1,4 3,4 1,3 1是逆序,逆序数是4。给出一个整数序列,求该序列的逆序数。Input第1行:N,N为序列...原创 2018-09-25 15:01:48 · 148 阅读 · 0 评论 -
51Nod 1013 3的幂的和
求:3^0 + 3^1 +...+ 3^(N) mod 1000000007Input输入一个数N(0 <= N <= 10^9)Output输出:计算结果Input示例3Output示例40题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013第一...原创 2018-09-20 15:54:25 · 115 阅读 · 0 评论 -
POJ1061 青蛙的约会
题目链接:http://poj.org/problem?id=1061实际上整个题目讲的就是拓展欧几里得算法求不定方程,===>ax+by=c,求这个方程的解。详细讲解:http://www.cnblogs.com/comeon4mydream/archive/2011/07/18/2109060.htmlhttps://blog.youkuaiyun.com/sxb0841901116...原创 2018-10-02 20:22:39 · 102 阅读 · 0 评论 -
nefu84 五指山
五指山Problem:84Time Limit:1000msMemory Limit:65536KDescription西游记中孙吾空大闹天宫,如来佛祖前来降伏他,说道:“我与你打个赌赛;你若有本事,一筋斗打出我这右手掌中,算你赢,再不用动刀兵苦争战,就请玉帝到西方居住,把天宫让你;若不能打出手掌,你还下界为妖,再修几劫,却来争吵。”那大圣闻言,暗笑道:“这如来十分好呆!我...原创 2018-10-05 10:46:48 · 321 阅读 · 0 评论 -
nefu117 素数个数的位数 (素数定理)
素数个数的位数Problem:117Time Limit:1000msMemory Limit:65536KDescription小明是一个聪明的孩子,对数论有着很浓烈的兴趣。他发现求1到正整数10n 之间有多少个素数是一个很难的问题,该问题的难以决定于n 值的大小。现在的问题是,告诉你n的值,让你帮助小明计算小于10n的素数的个数值共有多少位?Input输入数据有...原创 2018-10-05 12:24:12 · 261 阅读 · 0 评论 -
Codeforces-Rebranding
The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to c...原创 2018-09-27 23:01:40 · 206 阅读 · 0 评论 -
51nod P1003 铺地毯
题目链接:https://www.luogu.org/problemnew/show/P1003题目描述为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯。一共有 nn 张地毯,编号从 11 到nn。现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上。地毯铺设完成后,组织者想知道覆盖地...原创 2018-10-13 17:33:07 · 154 阅读 · 0 评论 -
Sagheer and Crossroads
题目链接:http://codeforces.com/problemset/problem/812/A Sagheer and Crossroads Sagheer is walking in the street when he comes to an intersection of two...原创 2018-09-29 19:57:58 · 234 阅读 · 0 评论 -
POJ 3276 Face The Right Way(开关问题)
大神详解:https://blog.youkuaiyun.com/yiqzq/article/details/79845159题目链接:http://poj.org/problem?id=3276DescriptionFarmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing fo...原创 2018-10-23 17:54:43 · 142 阅读 · 0 评论 -
POJ 1426 Find The Multiple(bfs)
题目链接:http://poj.org/problem?id=1426DescriptionGiven a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You m...原创 2018-10-23 19:21:14 · 150 阅读 · 0 评论 -
POJ 3280 Cheapest Palindrome(动态规划)
题目链接:http://poj.org/problem?id=3280DescriptionKeeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID...原创 2018-10-31 19:30:33 · 130 阅读 · 0 评论 -
POJ 2385 Apple Catching
题目链接:http://poj.org/problem?id=2385 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac...原创 2018-10-30 14:04:19 · 162 阅读 · 1 评论 -
HDU 1068 Girls and Boys(二分图匹配)
题目传送门题意: n个同学,一些男女同学会有缘分成为情侣,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合中不存在有缘成为情侣的同学的最大同学数。思路:独立集:图的顶点集的子集,其中任意两点不相邻最大独立集 = 顶点数 - 最大匹配数由于本题是从整个点集搜索,并不是将点集分开成(A)(B),(1->2)(2->1)对称存...原创 2019-07-23 09:18:45 · 164 阅读 · 0 评论