上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 26 下一页
摘要: 一个很简单的题;方法一:二分。代码: 1 #include 2 #include 3 #define maxn 100005 4 using namespace std; 5 6 int num[maxn],n; 7 8 int main() 9 {10 freopen("input.txt", "r", stdin);11 freopen("output.txt", "w", stdout);12 scanf("%d",&n);13 for(int i=0;i 2 #include 3 阅读全文
posted @ 2013-10-10 16:37 Yours1103 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 首先能被2,5整除的数结尾必须是0;如果没有0肯定不行;然后判断他们的和ans%3:如果==0,直接从大到小输出就行;如果==1,要么删除它们之间最小的那个%3==1的,要么删除两个小的并且%3==2的;如果==2,要么删除它们之中最小的那个%2==2的,要么删除两个小的并且%3==1的;代码: 1 #include 2 using namespace std; 3 int n,d[10],a,u; 4 main() 5 { 6 cin>>n; 7 while(n--)cin>>a,++d[a],u+=a; 8 if(u%3) 9 {10 for... 阅读全文
posted @ 2013-10-10 11:40 Yours1103 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 动态规划;白书上的题,看了好久看不懂刘汝佳的解法;在网上无意中看到了大神的思路,比较好理解,膜拜!他的思路是这样的:设d[i]是n个数按顺时针方向分别从0开始编号,第一次删除0,以后每k个数删除一个,最后剩下的数。实际上d[i]就是顺时针偏移了多少位。状态转移方程:d[i] = (k - 1 + d[i-1]) % (n-1) + 1;(删了0后,剩下1,2,...,n,全部减1后得到0,1,2,...,n-1,所以原来该删k——>>k-1,顺时针偏移d[i-1]位,取模,加1后变回原来的编号)代码: 1 #include 2 #define maxn 10009 3 using 阅读全文
posted @ 2013-10-06 20:13 Yours1103 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 树形DP:要求找出树上距离为k的点的对数;对于每个节点,经过这个节点的符合条件的的点有两种:第一种:距离他为i的儿子和他爸爸中距离他爸爸为k-i-1;(不是符合的点对中的一个)第二种:他儿子中距离为其儿子为k-1的点;(此节点为符合条件的点对中的一个) 1 #include 2 #include 3 #define N 50009 4 using namespace std; 5 vectorvec[N]; 6 int dp[N][505]; 7 long long ans; 8 void dfs(int x,int f,int k) 9 {10 dp[x][0]=1;11 ... 阅读全文
posted @ 2013-10-06 19:14 Yours1103 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 三维DP 第K字典序从左向右找 根据dp数组的值算出每一位该打印什么代码: 1 #include 2 #include 3 using namespace std; 4 long long memo[9][221][221]; 5 long long solve(int n, int m, int last)//n划分成m个数最小值为last; 6 { 7 if(n==0) 8 { 9 if(m>=last) return 1;10 return 0;11 }12 long long &ret = memo[n][m][las... 阅读全文
posted @ 2013-10-06 18:36 Yours1103 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 一个简单的货郎担问题,用状态压缩dp可以解决;解法:d(i,S)=min{d(j,S-{j})+dis(i,j) | j belongs to S};边界条件:d(i,{})=dis(0,i).最终答案:d(0,{1,2,3```n-1})时间复杂度:O(n^2*2^b);代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int dp[1024][11],dis[11][11],posx[11],posy[11]; 7 8 int main() 9 {10 int t,x,y,n;11 ... 阅读全文
posted @ 2013-10-06 13:51 Yours1103 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 一个01背包问题;刚刚开始把题目看错了,以为物品的数目是有限的,然后让你求一个家庭里最多能够拿多个价值的东西;这样一来的话,这个题目就有点意思了;但是后来发现竟然是个简单的01背包问题 = =;代码: 1 #include 2 #define maxn 1007 3 #include 4 #include 5 using namespace std; 6 7 int price[maxn],weight[maxn],f[105]; 8 int main() 9 {10 int t,n,g,x;11 scanf("%d",&t);12 while(t--)13 ... 阅读全文
posted @ 2013-10-06 10:50 Yours1103 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 简单的博弈题,用dp解;每个人只能拿1,l,k个硬币;dp[i][j]表示第j个人拿是否能拿第i枚硬币;代码: 1 #include 2 #define maxn 1000007 3 using namespace std; 4 bool dp[maxn][2]; 5 int x,l,m,k; 6 7 int main() 8 { 9 scanf("%d%d%d",&k,&l,&m);10 for(int i=1;i=l)dp[i][j]|=1-dp[i-l][j^1];15 if(i>=k)dp[i][j]|=1-dp[i-k][j^1];1 阅读全文
posted @ 2013-10-06 10:14 Yours1103 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 又是个2-sat的模板题;反正评委的选择必须有一个是正确的,1错误,那么2就必须正确;这就是一个2-sat问题。直接上白书的模板啊,不过稍微要注意的一点是对于第一个点必须要选择,不然就违反了题意;代码: 1 #include 2 #define maxn 2005 3 #define maxm 4005 4 #include 5 #include 6 using namespace std; 7 struct twosat 8 { 9 int n;10 vectorg[maxn*2];11 bool mark[maxn*2];12 int s[maxn*2],c... 阅读全文
posted @ 2013-10-05 19:38 Yours1103 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 比赛的时候刷了一点小聪明,发现这个数列是卢卡斯数,一个递推关系像斐波拉契数列的数列;我不知道怎么证明,如果哪天无意中会证了再加上;这题唯一的难点就是大数运算;直接用JAVA代码: 1 import java.io.PrintWriter; 2 import java.math.BigInteger; 3 import java.util.Scanner; 4 5 public class Main { 6 Scanner scan=new Scanner(System.in); 7 PrintWriter out=new PrintWriter(System.out); 8... 阅读全文
posted @ 2013-10-05 16:30 Yours1103 阅读(255) 评论(0) 推荐(0) 编辑
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 26 下一页