HDU 1518 Square】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! #include <iostream> #include <cstdio> #include<algorithm> #include <cstring> using namespace std; ],visit[]; int l,n; int dfs(int…
Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square?   Input The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the numb…
Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number…
Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9588    Accepted Submission(s): 3127 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end…
解题思路:sum%4!=0    , max<sum/4 #include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>usingnamespace std;int a[100];bool vis[100],flag;int m,ave;bool dfs(int ans,int sum,int cnt){     if(sum==a…
题目链接 题目大意: 题意就是输入棍子的数量和每根棍子的长度,看能不能拼成正方形. #include <bits/stdc++.h> using namespace std; int n,m,sum,cur; ],vis[]; bool fp; bool mycmp(int a,int b){ return a>b; } void dfs(int s,int len,int num){ //当前位置,目前长度,成功条数 ){ fp=true;return; } ,,num+); //如果…
Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不然复杂度非常高. 因为M最大为20,所以,如果用DFS还是可以接受的. 由所有火柴棒的长度和,我们可以求出要组成正方形的边长.我们设边长为len.在搜索前,首先可以把边长为分数的,也就是火柴棒的长度和不能被4整除的,排除掉. 问题可以转化为从M个数中挑出4组和为len的数. 首先,从M个数中搜索出和…
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11375    Accepted Submission(s): 3660 Problem Description Given a set of sticks of various lengths, is it possible to join them e…
本题来自:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题意:输入几个长度,判断能否拼成正方形. 以下部分参考了网友代码,终于ac啦. #include <stdio.h> #include <string.h> #include <stdlib.h> ]; ]; int len,m; int comp ( const void *a, const void *b ){return * ( int * ) a - * (…
http://acm.hdu.edu.cn/showproblem.php?pid=5079 题意: n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色 问最大白色正方形边长分别为0,1,2,……n 的涂色方案数 令ans[i]表示最大白色正方形边长小于i的方案数 最大边长=i 的就是ans[i+1]-ans[i] 枚举sz,表示现在要求最大白色正方形边长<i的方案数 设dp[i][st] 表示前i行,状态为st的方案数 st内压缩了n-sz+1个数,其中的第j个数表示 从右往左数第j列,…
Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1398 Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Co…
Problem Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ...…
Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7883    Accepted Submission(s): 5332 Problem Description People in Silverland use square coins. Not only they have square shapes but…
Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values o…
Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5443    Accepted Submission(s): 1732 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end…
pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值总和为n的方案数 分析:这题能够用母函数的思想,对300以内的值进行预处理就可以 也可用全然背包思想求300以内的方案数 母函数: #include<stdio.h> int main() { int c1[305],c2[305],i,j,k,n; for(i=0;i<=300;i++){…
Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number of sticks. M intege…
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9728    Accepted Submission(s): 6668 Problem Description People in Silverland use square coins. Not…
Problem Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ...…
题目:给出n,求出最小的m,满足m^2  % 10^k = n,其中k=0,1,2 http://acm.hdu.edu.cn/showproblem.php?pid=4394 只要有一个x满足条件便行了 我们可以初步发现,某个数个位确定,那么平方的最后一位肯定是确定的,那么如果后两们确定,那么平方的最后两们也是确定的,这可以通过乘法的规律得到 那我们只需要BFS一下,不断地找满足最后指定位数的数,1位,2位,--直到找到第一个满足条件的. 注意这里可能是100001这种情况 所以记录当前数字大…
Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9903    Accepted Submission(s): 6789 Problem Description People in Silverland use square coins. Not only they have square shapes but…
题意:一个字符串被称为square当且仅当它可以由两个相同的串连接而成. 例如, "abab", "aa"是square, 而"aaa", "abba"不是. 两个长度相同字符串之间的 hamming distance是对应位置上字符不同的位数. 给定一行字符串和 m,输出字典序最小的字符串. 析:首先先用dp判断能不能形成这样的字符串,然后再打印出来,dp[i][j] 表示 i - 中间的数能不能改 j 个字符得到,最后打印…
题意:给出n个(不同长度的)棍子,问能不能将他们构成一个正方形. 策略:深搜. hdoj 1455的简化版 代码: #include <stdio.h> #include <string.h> #include <algorithm> #define M 25 using namespace std; int s[M], n, ans;//ans就是答案 bool vis[M]; int dfs(int cou, int cur, int pos){ //cou是已分配…
http://acm.hdu.edu.cn/showproblem.php?pid=2281 又是一道Pell方程 化简构造以后的Pell方程为 求出其前15个解,但这些解不一定满足等式,判断后只有5个满足的情况,直接判断即可 求法可以参照上一篇日志: http://www.cnblogs.com/Felix-F/p/3223323.html struct matrix { LL ma[][]; }; ; LL nn[],xx[]; matrix operator * (matrix a,mat…
Problem Description A string is called a square string if it can be obtained by concatenating two copies of the same string. For example, "abab", "aa" are square strings, while "aaa", "abba" are not. Hamming distanc…
Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8800    Accepted Submission(s): 5991 Problem Description People in Silverland use square coins. Not only they have square shapes but…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; ],n,El; ]; int dfs(int k,int pos,int nowlen) { int i,j; if(nowlen==El) { if(k==n) ; else nowlen=,pos=; } for(i=pos…
思路:从第一个数开始搜索,将其和与边长比对,相等则计数+1,计数达到3的时候说明可以组成,因为剩下那条必与边长相等,搜索过程注意剪枝,若某个数已被加入边长则不能重复计算,应将其标记,另外应在每一层递归时进行判断,看是否满足结束条件,以此来优化时间 #include<stdio.h> #include<string.h> int a[25],vis[25]; int con,temp,side,sum,flag,k; //con用来记录边数,temp存放暂时的边长,用来与目标边长比对…
DFS+剪枝.与HDOJ 1455如出一辙. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 25 int nums[MAXN], n, len, cnt; char visit[MAXN]; int comp(const void *a, const void *b) { return *(int *)b - *(int *)a; } int dfs(int cnt, in…
题意: 给一个字符串t ,求与这个序列刚好有m个位置字符不同的由两个相同的串拼接起来的字符串 s, 要求字典序最小的答案    分析: 把字符串折半,分成0 - n/2-1 和 n/2 - n-1 dp[i][j] 表示 第i位及之后的总代价为j可不可行 从第 n/2-1 位推回第 0 位, 若dp[0][m] = 1,则存在 然后贪心对每一位从'a'试到'z',选取接下来存在解的字符 #include <cstdio> #include <algorithm> #include…