POJ 3548 Restoring the digits】的更多相关文章

暴力搜索.注意题目说每个字母对应的数字不同,这句话表明最多只有10个字母,所以暴力DFS绝对不会TLE. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; ],t[]; ]; ]; ]; int tot; int flag; ]; void DFS(int x) { int i; if(x==tot) { t[]='\0';…
http://poj.org/problem?id=3373 Changing Digits Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2719   Accepted: 863 Description Given two positive integers n and k, you are asked to generate a new integer, say m, by changing some (maybe…
Last Digits Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2233   Accepted: 474 Description Exponentiation of one integer by another often produces very large results. In this problem, we will compute a function based on repeated expone…
题目链接 记录路径的DP,看的别人的思路.自己写的也不好,时间居然2000+,中间的取余可以打个表,优化一下. 写的各种错,导致wa很多次,写了一下午,自己构造数据,终于发现了最后一个bug. dp[i][j]表示前i位取余得到j,需要最少改变多少位. 这样可以得到最少改变多少位了,但是,还要保证,最小.学习别人的题解,开一个标记数组,先从后倒回来,把这些可以达到最小的路径都记录下来. 然后再从头找最小的那一条路径.这样就能保证,最小了. #include <cstdio> #include…
一開始写的高位往低位递推,发现这样有些时候保证不了第四条要求.于是又開始写高位往低位的记忆化搜索,又发现传參什么的蛋疼的要死.然后又发现高位開始的记忆化搜索就是从低位往高位的递推呀,遂过之. dp[i][j]记录在i位 且 余数为j时的最优解情况. dp[i][j].next表示当前的最优解是由哪一种状态转移过来的. 代码又写锉了.. #include <algorithm> #include <iostream> #include <cstring> #include…
这道题我是看了别人的题解才做出来的.题意和题解分析见原文http://blog.csdn.net/lyy289065406/article/details/6698787 这里写一下自己对题目的理解. 1. 根据k的最大范围直接搜索n最后5位的方法是错误的,因为它并不能保证所求结果为最小.因为题目要求最后结果m要尽量小,而改变n的高位能够得到更小的值.k<n的限制条件表明解必然存在,而我们搜索的最大可修改位数应该和n的位数len相等. 2. 最终结果m必须满足:最高位非0且与n位数相同 (m若等…
题目大意: 给出一个数n,求m,使得m的长度和n相等.能被k整除.有多个数符合条件输出与n在每位数字上改变次数最小的.改变次数同样的输出大小最小的.  共同拥有两种解法:DP解法,记忆化搜索的算法. 以后会更新记忆化搜索. 1.DP解法: 解题思路: DP[i][j]表示数n的前i位除以k余j最小改变几位. DP[len][0]就表示数n被k整除最小改变几位. 依据这个关系从后向前遍历DP数组能够找出全部满足条件的数的路径. 再依据关系从前往后输出. 以下是代码: #include <stdio…
SudoKu Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu POJ 2676 Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the c…
BFS算法与树的层次遍历很像,具有明显的层次性,一般都是使用队列来实现的!!! 常用步骤: 1.设置访问标记int visited[N],要覆盖所有的可能访问数据个数,这里设置成int而不是bool,基于一个考虑,多次循环时不用每次都清空visited,传递进去每次一个数字即可,比如第一次标记为1,判断也采用==1,之后递加即可. 2.设置一个node,用来记录相关参数和当前的步数,比如: struct node { int i; int j; int k; int s;//步数 }; 3.设计…
以前做过的题目了....补集+DP        Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4091   Accepted: 1811 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult,…
分段的概率DP+矩阵快速幂                        Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4180   Accepted: 1076 Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. Af…
Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20396   Accepted: 6817 Description "Kronecker's Knumbers" is a little company that manufactures plastic digits for use in signs (theater marquees, gas station price…
“模拟“题,运用哈希,不断地按照一定运算规律对一个结果进行计算,如果重复出现就停止并且输出该数.注意到仔细看题,这种题一定要细心! POJ - 2183 Bovine Math Geniuses Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description Farmer John loves to help the cows further their mathematical skills…
POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description Implement a ranking program similar to the one used for this programming contest. Input The input …
POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the…
POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accepted: 2964 Description You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would…
  POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted: 9153 Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change…
POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Accepted: 10613   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representati…
A - 487-3279 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1002 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spel…
http://poj.org/problem?id=1151 经典矩形面积并吧.....很简单我就不说了... 有个很神的地方,我脑残没想到: 将线段变成点啊QAQ这样方便计算了啊 还有个很坑的地方,为毛每一次我精确地计算过空间可就是wa....一改大就ac...我无力了.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostrea…
http://poj.org/problem?id=3070 根据本题算矩阵,用快速幂即可. 裸题 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> using namespace std; #define rep(i, n) for(int i=0; i<…
这里的算法非常简单,就是“模拟”,注意编写每个传令官的算法时先分开测试,放在一起就会混淆. POJ - 2041Unreliable Message Time Limit: 1000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Description The King of a little Kingdom on a little island in the Pacific Ocean frequently has childis…
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5337   Accepted: 2277 Description The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form…
链接:http://poj.org/problem?id=1064 Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23896   Accepted: 5118 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee ha…
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8173   Accepted: 2423 Description Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices…
链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14952   Accepted: 4189 Description You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orth…
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University, noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that nu…
E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil rep…
Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5457   Accepted: 2400 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp…
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,…