摘要: 我一开始是打算通过看数据,查找规律的,但是觉得这样很麻烦,即使看出来,那也没有掌握到其中的思想,加之没有思路,所以我干脆看了人家的答案人家的题解其实本题函数递归都给我们了。但是就是说,要用一般简单的函数的话,就会超时(我试过。)然后我参考了别人博客构造一个三维数组"int d[a][b][c]",用来记忆。真的用到的是后面“ if(d[a][b][c]) return d[a][b][c];”只要曾经算过得就可以记下了。减少了计算时间了!#include "iostream"#include "string.h"using names 阅读全文
posted @ 2013-08-28 13:47 龙城星 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 完完全全地一道水题,以后不做这种题目了,用十几行就可以解决的问题啊#include "iostream"#include "string.h"using namespace std;int main(){ int ncase,n,i; cin>>ncase; while(ncase--){ cin>>n; for(i=2;;i++){ if((i+1)*(i+1)-1>=n){ cout<<i<<endl; break; } } }} 阅读全文
posted @ 2013-08-28 11:01 龙城星 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 又是一道坑爹的题目,明明数据都通过了,就是wrong anser#include "iostream"#include "string.h"using namespace std;struct { int x,index;}dp[1000];int find(int low,int high,int a){ while(low=a)low=mid+1; else high=mid-1; } return low;}int main(){ int n,i,num[1000],k,x,set[1000],len,longth; while(cin>&g 阅读全文
posted @ 2013-08-28 10:13 龙城星 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 不知道错在哪里#include "iostream"#include "string.h"#include "algorithm"#define INF 0x3fffffff;using namespace std;int min(int a,int b){return a>b?b:a;}int main(){ int n,m,i,num[110],sum[110][110],j,dp[110][110],k,top=1; while(cin>>n>>m){ if(!n&&!m)break 阅读全文
posted @ 2013-08-27 21:57 龙城星 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 我的代码超时了,用太多for了#include "iostream"#define INF 10000000;using namespace std;int min(int a,int b){return a>b?b:a;}int main(){ int n,m,num[320],v,i,j,k,sum,g[320][320],l,dp[320][320]; while(cin>>n>>m){ for(i=1;i>num[i]; for(v=0;v0?num[k]-num[l]:num[l]-num[k]); } g[i][j]=min( 阅读全文
posted @ 2013-08-27 19:42 龙城星 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 代码有点长,不过ACCEPT了创新点是输入时,用set数组来表示第t秒x个位置上下了一个饼看了人家给得特殊例子,发现一个问题,当第i秒没有饼下来,或者第i秒饼下的位置人没有走到,这两种特殊情况,所以就加了以下的几行代码if(set[i][j-1]!=0&&j-1>=0)dp[i][j-1]=max(dp[i][j-1],dp[i-1][j]+set[i][j-1]); if(set[i][j]!=0)dp[i][j]=max(dp[i][j],dp[i-1][j]+set[i][j]); if(set[i][j+1]!=0&&j+1=0)dp[i][j-1 阅读全文
posted @ 2013-08-25 22:44 龙城星 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 又一道水题,找出规律就行了#include "iostream"using namespace std;int work(int m,int n){ //cout>m>>n){ cout<<work(m,n)<<endl; }} 阅读全文
posted @ 2013-08-25 21:07 龙城星 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 比我的代码更好的提示typedef struct{ intw,s; intlen,index; intbefore;}mice;建立数据结构时,用index来记录真实的位置,用before来记录排序后,这个元素上一个元素的位置max=m[j].len;flag=j;用j来表示最大的那个数贴上我ACCEPT的代码吧#include "iostream"#include "algorithm"using namespace std;struct student{ int weight,speed;}num[1000],s[10000];struct{ int 阅读全文
posted @ 2013-08-25 19:48 龙城星 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 我有两个想法,其中一个超时,另外一个不知道怎么表达,结果悲剧地看了答案,可惜正确的答案跟我的想法一样ACCEPT#include #include #include using namespace std;const int N = 10000;const int inf = 0xfffffff;int mon[13];int dp[13][N];int main(){ //freopen("data.in", "r", stdin); int m, i, j, k; while(scanf("%d", &m), m) { i 阅读全文
posted @ 2013-08-25 17:05 龙城星 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 跟之前做过的最大m子段一样的原理,不过这道题容易些dp[i][j]=max(dp[i-1][j-data[i]]+sum1[j]-sum1[j-data[i]],dp[i][j-1]);第j个数是否加入第i子段,两种情况取最大就行了#include "iostream"#include "string.h"#define INF 10000000;using namespace std;int max(int a,int b){return a>b?a:b;}int dp[1000][1000];int main(){ int n,m,i,sum[ 阅读全文
posted @ 2013-08-24 12:14 龙城星 阅读(158) 评论(0) 推荐(0) 编辑