Discrete Logging(poj 2417)】的更多相关文章

高次同余方程.   BL == N (mod P)求解最小的L. /* A^x=B(mod C) 设x=i*m-j(其中m=ceil(sqrt C)) 并且i∈[1,m],j∈[0,m],以保证x能取到所有的0~C-1之间的数. 为什么只取到0~C-1就行了呢? 根据费马小定理 a^(p-1)=1(mod p)(p是素数),我们可以得到 a^(k mod p-1)=a^k(mod p) 即当k>p-1时,会出现类似于循环节的东西. 那么我们可以得到变形之后的式子 A^(i*m-j)=B(mod…
Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2819   Accepted: 1386 Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 1 <= N < P, compute the discrete logarithm of N, b…
d. 式子B^L=N(mod P),给出B.N.P,求最小的L. s.下面解法是设的im-j,而不是im+j. 设im+j的话,貌似要求逆元什么鬼 c. /* POJ 2417,3243 baby step giant step a^x=b(mod n) n是素数或不是素数都可以 求解上式 0<=x<n的解 */ #include<iostream> #include<stdio.h> #include<string.h> #include<math.…
Discrete Logging Given a prime P, 2 <= P < 2 31, an integer B, 2 <= B < P, and an integer N, 1 <= N < P, compute the discrete logarithm of N, base B, modulo P. That is, find an integer L such that B L == N (mod P) Input Read several line…
Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; ],b[]; ]; int main() { int n,m,i,j; while(scanf("%d%d",&n,&m)!=EOF) { ;i&l…
Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5565   Accepted: 1553 Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties,…
日志分成几个常用的级别 debug 10 代表程序调试过程中的信息 info 20 代表普通日志信息,用户的访问等等 warning 30 警告日志,有可能出错,但是目前还没出错的 error 40 程序明确的错误 critical 50 软件崩溃等严重的问题产生的日志 日志特点:向上传递 比如日志级别设置成30,那么30以下的则不会输出 日志实例 比如我需要产生相关级别的日志 logging.debug('debug...') logging.info('info...') logging.w…
在一个软件中,日志是可以说必不可少的一个组成部分,通常会在定位客户问题或者记录软件使用情况等场景中会用到.logging模板块是Python的一个内置标准库,用于实现对日志的控制输出,对于平常的日志输出,甚至是系统级的日志输出,也都可以使用logging模块来进行实现. 一.使用basicConfig进行简单的一次性配置 basicConfig一次性配置,简单示例: # -*- coding:utf-8 -*- import logging import datetime # filename:…
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) http://poj.org/problem?id=2488   (A Knight's Journey) (不知道为什么,名字竟然不同哇~~~~还是poj 改名改得好) 题目意思:给出一个p * q 的棋盘,行用阿拉伯数字1,2,...,p-1, p 来表示,列从大写字母'A'开始表示.我这里为了简化…
取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37662   Accepted: 12594 Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后把石子全部取完者为胜者.现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者…
题目:Find The Multiple 题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数. 思路:nonzero multiple  非零倍数  啊. 英语弱到爆炸,理解不了题意..... STL 在c++过不了,  一直TLE, 最后只好看了下大神的代码. #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <c…
题目:食物链 题意:给定一些关系.判断关系的正确性,后给出的关系服从之前的关系: 思路:难点不在并查集,在于关系的判断,尤其是子节点与根节点的关系的判断: 这个关系看似没给出,但是给出子节点与父节点的关系AND父节点与根节点的关系之后,子节点与根节点的关系是可以确定的. Rank[]存的是与父节点的关系,0是同类,1是被吃,2是吃 1.若Find(x) == Find(y) ,则x y有关系,直接判断关系: 1)  d == 1, Rank[x] == Rank[y] ,  否则fake++:…
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低要求.酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币.如果你能够弄来他的水晶球,那么只要5000金币就行了."探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,他可以降低价格.探险家于是又跑到其他地方,其他人也提出了类似的要求…
Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3064   Accepted: 1505 Case Time Limit: 2000MS   Special Judge Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material s…
题目大意,给出一个字符串s,求最大的k,使得s能表示成a^k的形式,如 abab 可以表示成(ab)^2: 方法:首先 先求kmp算法求出next数组:如果 len mod (len-next[len])==0 ,答案就是 len /(len-next[len]),否则答案是1:证明如下: 如果s能表示成 a^k的形式且k>1,k尽可能大,即s可以表示成aaaaaa(k个a):那么next[len]就等于k-1个a的长度:aaaaaaa  aaaaaaa那么 (len-next[len])a的长…
Calculate the number of toys that land in each bin of a partitioned toy box. 计算每一个玩具箱里面玩具的数量 Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toy…
扫描线算是线段树的一个比较特殊的用法,虽然NOIP不一定会考,但是学学还是有用的,况且也不是很难理解. 以前学过一点,不是很透,今天算是搞懂了. 就以这道题为例吧:嘟嘟嘟 题目的意思是在一个二维坐标系中给了很多矩形,然后求这些矩形的总覆盖面积,也就是面积并. 我就不讲暴力,直接切入正题吧. 扫描线,听这个名字就可以想象一下,现在有这么多重叠的矩形,然后有一个线从下往上扫,那么每一时刻这条线上被覆盖的长度之和,就是我们要求的答案. 那么首先可以想到,要把给定的矩形都离线下来,拆成上下来个面,并标记…
题意:给一颗n个节点的树,每条边上有一个距离v(v<=1000).定义d(u,v)为u到v的最小距离.给定k值,求有多少点对(u,v)使u到v的距离小于等于k. /* 照着点分治模板敲了敲,有很多细节地方应该注意,不然很容易出错. 点分治的大概就是解决树上路径中统计某些东西的一个算法,顾名思义,肯定与递归有些关系. 简单步骤就是:①求重心 ②统计这棵树的答案 ③递归到它的子树求解 推荐一篇博客:http://www.cnblogs.com/chty/p/5912360.html */ #incl…
Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 1 <= N < P, compute the discrete logarithm of N, base B, modulo P. That is, find an integer L such that B L  == N (mod P) Input Read several lines of…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3239 [题目大意] 计算满足 Y^x ≡ Z ( mod P) 的最小非负整数 [题解] BSGS裸题. [代码] #include <cstdio> #include <cmath> #include <map> #include <algorithm> #include <tr1/unordered_map> using name…
http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffee at coffee vending machines at motorests. Charlie hates change. That is basically the setup of your next task. Yo…
1703 -- Find them, Catch them http://poj.org/problem?id=1703 题目大意:有2个敌对帮派,输入D a b表示a,b在不同帮派,输入A a b表示询问a,b是否是在一个帮派. 题解:因为并查集中的元素均是有联系的,否则也不会被合并到当前集合中.那么我们就把这2个元素之间的关系量转化为一个偏移量, 假设x->y 偏移量0时 x和y同帮派 x->y 偏移量1时 x和y不同帮派 不妨继续假设,x的当前集合根节点tx,y的当前集合根节点ty. 如…
题目链接 :http://poj.org/problem?id=3177 Description In order to <= F <= ,) grazing fields (which are numbered ..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often bei…
题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique am…
http://poj.org/problem?id=1661 Description "Help Jimmy" 是在下图所示的场景上完成的游戏. 场景中包括多个长度和高度各不相同的平台.地面是最低的平台,高度为零,长度无限. Jimmy老鼠在时刻0从高于所有平台的某处开始下落,它的下落速度始终为1米/秒.当Jimmy落到某个平台上时,游戏者选择让它向左还是向右跑,它跑动的速度也是1米/秒.当Jimmy跑到平台的边缘时,开始继续下落.Jimmy每次下落的高度不能超过MAX米,不然就会摔死…
http://poj.org/problem?id=1015   Description In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, which is do…
http://poj.org/problem?id=1127   Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one without disturbing the other straws. Here, we are only concerned wi…
http://poj.org/problem?id=1006      在<孙子算经>中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2), 问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”.具体解法分三步: 1.找出三个数:从3和5的公倍数中找出被7除余1的最小数15,从3和7的公倍数中找出被5除余1 的最小数21,最后从5和7的公倍数中找出除3余1的最小数70. 2.用15乘以2(2为最终结果…
Eight Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one ti…
题意: 给你一张有向图,你可以选择一个点:• 摧毁其所有的入边,代价A[i].• 摧毁其所有的出边,代价B[i].• 求摧毁这张图的最小代价.• 数据范围1000 /* 很经典的一道题目(我这么弱,稍微一变形就不会了) 因为每个点涉及到出边和入边,所以可以考虑拆点,然后建图,接下来就成了一个最小点权覆盖的问题. 最小点权覆盖就是求最小割(证明可参考胡伯涛论文"最小割模型在信息学竞赛中的应用"). 接下来是输出方案,因为我们要选择的点与S或T连得边是满流的,所以可以dfs一边,只走不满流…