URAL - 1495 One-two, One-two 2】的更多相关文章

URAL - 1495 这是在dp的专题里写了,想了半天的dp,其实就是暴力... 题目大意:给你一个n,问你在30位以内有没有一个只由1或2 构成的数被 n 整除,如果 有则输出最小的那个,否则输出Impossible. 思路:因为位数是30,所以我们不能直接暴力,这样的复杂度是2^30次.那么其实我们 可以分段暴力,我们只要求出15位的所有余数的最小值,我们再处理处由15数字组成的余数, 如果答案超过十五位,我们枚举超过15位部分的余数,找对应需要的余数. #include<bits/std…
题目连接 排行榜 A和I都是签到题 按位BFS K Yet Another Multiple Problem 题意:给一些可以用的数字,求最小的数,它由特定的数字组成且是n的倍数 分析:暴力枚举不可行,因为数字可能非常大.考虑到大数取模为0,BFS每一层即数位,递归输出路径. #include <bits/stdc++.h> const int N = 1e4 + 5; bool no[10]; std::pair<int, int> pre[N]; int dir[10]; bo…
直达–> HDU 1495 非常可乐 相似题联动–>POJ 3414 Pots 题意:中文题,不解释. 思路:三个杯子倒来倒去,最后能让其中两个平分即可.可能性六种.判定的时候注意第三个杯子不能有水,倒的时候也要注意别超过了倒进去的杯子的容积. a->b || a->c || b->a || b->c || c->a || c->b #include <cstdio> #include <cstring> #include <q…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=103711#problem/M /*BFS简单题 链接地址: http://acm.hdu.edu.cn/showproblem.php?pid=1495 思路:预处理m < n < s,以后处理方便点 初始状态,m,n杯中可乐体积为0,s杯中体积为s; 然后分六种情况: 1, s 倒 m 2, s 倒 n 3, m 倒 n 4, m 倒 s 5, n 倒 m 6, n 倒 s 直到n…
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即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…