1049. Brave Balloonists Time limit: 2.0 secondMemory limit: 64 MB Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this event and open a bottle of champagne. Unfortunately,…
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets running east to west bound them. A helicopter took off in the most southwestern crossroads and flew along the straight line to the most northeastern…
1049 求约数的个数 质因子数的个数+1相乘 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<cmath> using namespace std; #define N 10000 ],a[],p[N+],g,o[N+]; void init() { int i,j; ; i…
1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime numbers? Very easily: prime numbers are the number 2 and all the odd numbers greater than 2. They may show that this definition corresponds to the mathem…
URAL题解三 URAL 1045 题目描述:有\(n\)个机场,\(n-1\)条航线,任意两个机场有且只有一种方案联通.现有两个恐怖分子从\(m\)号机场出发,第一个人在机场安装炸弹,乘坐飞机,引爆炸弹,在另一个机场降落,然后到第二人做一样的事,轮流做,直到某个人做不到就输.一个机场炸了后,任何与它相连的航线都不复存在.问第一个人能不能赢,如果能,则输出他第一个要飞到的机场,如果不能则输出First player loses solution 博弈论,输赢状态的搜索. 时间复杂度:\(O(n)…
题目链接 题意 : 给你一个数,未知进制,然后让你从2到36进制中找出一个最小的进制K,满足给你的这个数作为k进制时能够整除k-1. 思路 : 有一个公式,(a*b^n)mod(b-1)=a: 给定你这个数,当做字符串输入的时候,这个数转化成10进制的结果应该是:a[0]*k^(n-1)+a[1]*k^(n-2)+……+a[n-1]*k^0,然后题目要求的就是这个式子的结果取余(k-1)为0, 经过最开始给出的公式,将该式子化简得(a[0]+a[1]+……+a[n-1])%(k-1),所以只要满…
题目链接 题意 :给你a,b,n,让你找出两个数x,y,使得n-(a*x+b*y)最小. 思路 : 分大小做,然后枚举a的倍数 #include <stdio.h> #include <string.h> #include <iostream> #define LL __int64 using namespace std ; int main() { LL a,b,n ; while(~scanf("%I64d %I64d %I64d",&a…
题目链接 题意 : 一个学生梦到自己在一条有很多酒吧的街上散步.他可以在每个酒吧喝一杯酒.所有的酒吧有一个正整数编号,这个人可以从n号酒吧走到编号能整除n的酒吧.现在他要从a号酒吧走到b号,请问最多能喝到多少酒. 思路 :因为b肯定要是a的倍数,是a从头开始乘下去的,实际上就是找构成b/a的素数划分,有多少个素数划分就可以喝到多少的酒. #include <stdio.h> #include <string.h> #include <iostream> using na…
题目链接 题意 :给你第 i 项的值fi,第 j 项的值是 fj 让你求第n项的值,这个数列满足斐波那契的性质,每一项的值是前两项的值得和. 思路 :知道了第 i 项第j项,而且还知道了每个数的范围,二分求第 i+1项,然后根据性质求下去,求到第 j 项的时候看看通过二分求出来的值与给定的第j项的值大小关系,来确定下一次二分的值,输出的时候注意方向. #include <stdio.h> #include <string.h> #include <iostream> #…
Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is enough to conjure wonderful gardens or a fireball to burn your enemies to ashes? The reality is a little more complicated than that. To master skills,…
题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军韩信带领1500名士兵经历了一场战斗,战死四百余人.韩信为了清点人数让士兵站成三人一排,多出来两人:站成五人一排,多出来四人:站成七人一排,多出来六人.韩信立刻就知道了剩余人数为1049人. 小Hi:韩信点兵嘛,这个故事很有名的. 小Ho:我觉得这里面一定有什么巧妙的计算方法!不然韩信不可能这么快计…
嗯,写这个是因为我太弱了\(ORZ\). #\(\mathcal{\color{silver}{1 \ \ Linear \ \ Sieve \ \ Method \ \ of \ \ Prime}}\)线性筛素数 嗯,其实对于这个而言,无非就是一个\(break\)不易理解而已. if(! (i % prime[j])) break ; 那么我们先来分析线性筛的复杂度,嗯,很显然因为是\(O(n)\)才称其为线性筛法.所以也就是说,对于每个合数,我们只让它被筛去一次.那么线性筛是如何保证的呢?…
十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻. 今天,大家选择上机考试,就是一种勇敢(brave)的选择:这个短学期,我们讲的是博弈(game)专题:所以,大家现在玩的也是"勇敢者的游戏",这也是我命名这个题目的原因. 当然,除了"勇敢",我还希望看到"诚信",无论考试成绩如何,希望看到的都是一个真实的结果,我…
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据,看看有没有结论. 2 3 4 5 6 7 8 9 10 11 12 (人数) 1 2 2 3 3 3 4 4 4 4 4 (比赛数) 发现比赛数的增长成斐波那契.维护一个前缀和即可. #include <bits/stdc++.h> #define ll long long using names…
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .in. 输入共n + 2 行. 第一行包含2 个整数n .m ,每两个整数之间用一个空格隔开. 接下来的n+1 行每行包含一个整数,依次为a0,a1,a2..an 输出格式: 输出文件名为equation…
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不重要,重要的她代表的含义,其实呢,gcd(a,b)就表示 非负整数 a 和 b(不同时为0) 的最大公约数,(数论概论上说:计算 a 与 b 的最大公因数的更低效方法是我女儿四年级老师教的方法,老师要求学生求出 a 与 b 的所有因数,然后找出同时出现在两个表中的最大数字. YES!A good idea f…
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2269    Accepted Submission(s): 851 Problem Description Diophantus of Alexandria was an egypt mathematician living in Ale…
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status][Discuss] Description  一种非对称加密算法的密钥生成过程如下: 1.任选两个不同的质数p,q 2.计算N=pq,r=(p−1)(q−1) 3.选取小于r,且与r互质的整数e 4.计算整数d,使得ed≡1KQ/r 5.二元组(N,e)称为公钥,二元组(N,d)称为私钥 当需要加…
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long int64; ]; int64 A,B,K,pi,pk,ans,ti,q; int64 ksm(int64 x,int64 y){ ) ; ) return x; int64 d=k…
题目链接: 传送门 Brave Game Time Limit: 1000MS     Memory Limit: 65536K 题目描述 各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的: 1. 本游戏是一个二人游戏; 2. 有一堆石子一共有n个: 3. 两人轮流进行; 4. 每走一步可以取走1-m个石子: 5. 最先取光石子的一方为胜: 如果游戏的双方使用的都是最优策略,请输出哪个人能赢 思路 巴什博弈 只有一堆n个石子,两个人轮流从这堆石子中子,规定每次至少取一个,最多取m个.最…
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dtyfc.com/acm/980 我看的这个学会的…… 可以先求不满足要求的三元组数量,也就是abc,a和b互质,b和c不互质. 这样就要找这n个数中,和某个数不互质的数的个数. 可以质因数分解+容斥原理,求出和某个数不互质的数的个数(也就是和这个数有相同因数的数的个数). 还要先预处理以某个数x为因子…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAN0CAIAAAA4f3koAAAgAElEQVR4nO3dO3LbyNoG4H8TyrUQx1…
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串中心位置,RMQ询问LCP = min (height[rank[l]+1] to height[rank[r]]),注意的是RMQ传入参数最好是后缀的位置,因为它们在树上的顺序未知,且左边还要+1. #include <cstdio> #include <algorithm> #in…
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and each orders a juice cocktail. It could be from 1 to 3 different juices in each cocktail. There are three juices in the bar: apple, banana and pineappl…
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best programmer in the world! Now he regularly takes part in various programming contests, attentively listens to problems analysis and upsolves problems. But…
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate integers together in their spare time. Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting i…
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome music video ever for their new single. In that music video Ilya will go through Manhattan standi…
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in process, manpower and supplies are coming to an end and the winter is as near as never before. The game of thrones is unpredictable so Daenerys and Stannis…
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. According to a proverb, every man to his own taste. So the children value strawberries and raspberries differently. Let’s say that i-th child rates hi…
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a very serious mathematician and he likes to solve serious problems. This is another problem from Alex. You are given three nonnegative integers a, b, c.…