fzu 2125】的更多相关文章

现在有一个等式如下:x^2+s(x,m)x-n=0.其中s(x,m)表示把x写成m进制时,每个位数相加的和.现在,在给定n,m的情况下,求出满足等式的最小的正整数x.如果不存在,请输出-1. Input 有T组测试数据.以下有T(T<=100)行,每行代表一组测试数据.每个测试数据有n(1<=n<=10^18),m(2<=m<=16). Output 输出T行,有1个数字,满足等式的最小的正整数x.如果不存在,请输出-1. Sample Input 4 4 10 110 10…
Problem Description 现在有一个等式如下:x^2+s(x,m)x-n=0.其中s(x,m)表示把x写成m进制时,每个位数相加的和.现在,在给定n,m的情况下,求出满足等式的最小的正整数x.如果不存在,请输出-1.  Input 有T组测试数据.以下有T(T<=100)行,每行代表一组测试数据.每个测试数据有n(1<=n<=10^18),m(2<=m<=16).  Output 输出T行,有1个数字,满足等式的最小的正整数x.如果不存在,请输出-1.  Sam…
#include<stdio.h> #include<math.h> int total(int x,int m) { int sum=0; while(x>0) {  sum+=x%m;  x/=m; } return sum; } int main() {   __int64 n,suma,i;   int m,t,ans,j,h; scanf("%d",&t); while(t--) { scanf("%I64d%d",&…
Problem 2125 简单的等式 Time Limit: 1000 mSec Memory Limit : 32768 KB  Problem Description 现在有一个等式如下:x^2+s(x,m)x-n=0.其中s(x,m)表示把x写成m进制时,每个位数相加的和.现在,在给定n,m的情况下,求出满足等式的最小的正整数x.如果不存在,请输出-1.  Input 有T组测试数据.以下有T(T<=100)行,每行代表一组测试数据.每个测试数据有n(1<=n<=10^18),m(…
思路:x绝对小于根号n,再由s(x,m)可以缩小范围.1e9十六进制大约算出每位和相加100左右.这种题直接判断范围再暴力. #include<stdio.h> #include<string.h> #include<algorithm> #include<cmath> #include<cstdlib> #include<iostream> #define LL long long using namespace std; int…
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有lcp(i-L,i+1)>=L那么就可以更新答案 复杂度  建立SA,LCP等nlogn,枚举X及向两边延伸26*n #include<iostream> #include<algorithm> #include<cstdio> #include<cstring…
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个数列的这n种变换里, A(0): a1,a2,-,an-1,an A(1): a2,a3,-,an,a1 - A(n-2): an-1,an,-,an-3,an-2 A(n-1): an,a1,-,an-2,an-1 问有多少个变换里,所以前缀和都是正整数. 思路:因为变换是a[n]后面接着a[1]所以我们把…
 FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Practice Description Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation 1: AND opn L R Here opn, L and R are intege…
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设有n个连通分量,我们就需要n-1条边把他们连起来. 最后对于每个联通分量来说,我们要使它能一次走完,就是要求他是否满足欧拉通路,也就是这个联通分量中至多有2个度为奇数的点,每多出2个度为奇数的点,就多需要一条边(因为单个连通分量的所有点的度数之和为偶数,所以不可能存在奇数个奇数度数的点). #inc…
FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Practice  Description Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisl…
 FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Practice Description You have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction betwee…
 FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Practice Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-nega…
 FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Practice Description Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sk…
Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2150 Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning,…
Description   Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a sin…
Problem 1686 神龙的难题 Accept: 397    Submit: 1258Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description 这是个剑与魔法的世界.英雄和魔物同在,动荡和安定并存.但总的来说,库尔特王国是个安宁的国家,人民安居乐业,魔物也比较少.但是.总有一些魔物不时会进入城市附近,干扰人民的生活.就要有一些人出来守护居民们不被魔物侵害.魔法使艾米莉就是这样的一个人.她骑着她的坐骑,神龙米格…
告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题都还没看就结束了....赛后一看,果断是重复覆盖... 不过之后一直没敲...然后今天算是补回来吧,同时也把好久以前学的DLX复习一下... DLX的话,双向十字链表...具体的话,百度Google什么的dancing links... 一开始敲的时候还是挺顺利的,因为之前做过几次重复覆盖都是直接拿精确覆盖的…
串结构练习——字符串匹配 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2125 题目描述   给定两个字符串string1和string2,判断string2是否为string1的子串.   输入  输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表stri…
 FZU 2148  Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimen…
FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this bo…
http://acm.fzu.edu.cn/problem.php?pid=1977 题意:n×m的网格,有3种格子,'O'必须经过.'*'可以选择经过.'X'不能经过.现在要求路径经过所有'O'且是简单回路的数量 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; struct H { static const int…
/****************************************************************** 题目: 志愿者选拔(FZU 1894) 算法: 单调队列 算法思想: 在每个元素入队的时候入队的时候,使队列单调,查找 的时候就能很快找到最值. *******************************************************************/ #include<cstdio> #include<cstring>…
http://acm.fzu.edu.cn/problem.php?pid=2214   Problem Description Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the items into a knapsack so that the total weight is less than or equal to a given limit B a…
http://acm.fzu.edu.cn/problem.php?pid=2225   Problem Description 在打败了易基•普罗布朗.诺姆•普罗布朗之后,小茗同学开始挑战哈德•普罗布朗. 一番交战之后,哈德展开了一大波攻击.小茗同学为了抵御攻击,一边放魔法阵一边放魔法阵,然后他也不知道自己一共放了几个魔法阵.回收魔法阵是需要花费时间的,为了抵御下一波攻击,小茗同学需要知道自己共放了几个魔法阵,由于情况紧急,这个任务需要由你来完成. 魔法阵是三角形△的,比如 .........…
http://acm.fzu.edu.cn/problem.php?pid=2233 Problem Description 为了帮助柯南回到一米七四,阿笠博士夜以继日地研究APTX4869的解药.他得出了如下结果: 1.解药由n种原料构成: 2.对于两种不同的的原料a,b,它们之间有个影响值f(a,b): 3.需要把原料分成两个部分X,Y,每部分中至少有一种原料: 4.解药的效果由分别属于X,Y的原料之间,最小的影响值决定,即 效果=min{f(a,b)|a∈X,b∈Y)} 博士需要你帮忙求出…
C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1649 Description Your task is simple.Give you a number N, you should judge whether N is a prime number or not. Input There…
云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 思想是很好想的..唯一的难点大概是 c++里面没有同或这种东西 得自己写 而我又不怎么会位运算 问了蕾姐半天也没搞懂怎么用~这个取反符号 到最后怒而手写了函数 一开始想的是 init后 输入nm都可以秒出 但是在使用~的路途上 发现至少我的方法 做这个题 不能做到init后随便输入 因为 每行 都有…
题意 给出一个数字组成的立方体 在其中选取一个体 使这个体中的数字之和最小 不可以不选 fzu的题目分类动态规划里面不是按难度排得 是按照题号..记得以前做题碰到过算 矩阵里面求子矩阵的最大和的 不会 然后这次看着这个三维的..内心是崩溃的 幸好看了一眼范围 亮点是1<=n<=20 那直接处理一下暴力就可以了... 我们可以用一个dp[i][k][j]来记录 从1.1.1到i.k.j 之间的体的和 然后我们可以进行枚举每个体 处理的时间复杂度可以忽略 实际枚举的复杂度是n^6 但是做题的时候没…
http://acm.fzu.edu.cn/problem.php?pid=2188 过河I Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2188 Description 一天,小明需要把x只羊和y只狼运输到河对面.船可以容纳n只动物和小明.每次小明划船时,都必须至少有一只动物来陪他,不然他会感到厌倦,不安.不论是船上还是岸上,狼的数…
http://acm.fzu.edu.cn/problem.php?pid=2146  Problem 2146 Easy Game Accept: 661    Submit: 915Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game on a string S. Now the…