12 2012 档案
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1833思路:动态规划f[i-1][j]=max(f[i-1][j]+f[i][j],f[i-1][j]+f[i][j+1])#include <stdio.h>int arr[1000][1000];int max(int a,int b){ if(a>=b) return a; else return b;}int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { for(int j=0;j&l
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1834求既是回文数又是质数的数思路:先求出100000以内的所有质数,然后判断回文数再判断质数#include<stdio.h>int p[100000]={2};int num;int reverse(int n){ int t=0; if(n>=10) { while(n>0) { t=t*10+n%10; n/=10; }return t; } else return n;}int prime(){ int count...
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1828 * * * x * * ------- * * * * * * ------- * * * *用给定的数字来取代*,求式子成立的个数思路:枚举法,我的做法是将111*11到999*99全部枚举,也可将输入的数字排列枚举。#include <stdio.h>#include <stdlib.h>int arr[10];int ans=0;int n;int inarr(int x){ int num; if(x/100==0) num=2...
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1826用个数固定总长最小的几块木板 覆盖不连续的区间 求木板总长思路:快排 贪心法#include <stdio.h>#include <stdlib.h>int arr[210];int gap[210];int cmp(const void *a,const void *b){ return *(int*)a-*(int *)b;}int main(){ int ans=0; int m,s,c; scanf("%d%d%d",&m,&s,&
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1825制造商从多个原材料提供商获取原材料,使费用最小思路:快排,贪心法#include <stdio.h>#include <stdlib.h>struct milksuply{ int cost; int num;}suply[5005];int cmp(const void *a,const void *b){ return ((milksuply *)a)->cost-((milksuply *)b)->cost;}int main(){ int n,m; sca
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1820输入n个区间取并集,求最长的区间和最长的区间间隔。思路:快排 另外一开始没考虑到如果只有一个区间的情况#include <stdio.h>#include <stdlib.h>struct worktime{ int start; int end;}time[5005];int cmp(const void *a,const void *b){ return ((worktime *)a)->start-((worktime *)b)->start;}int ma
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1819从一串项链某一点向左右分别取珠子,直至颜色不同。思路:珠子的个数最大350,用枚举法;对项链处理可将项链复制后头尾相连存入数组;最后如果统计出的个数超过n,则输出n;#include <stdio.h>char beads[360];int main(){ int n; int ans=0; scanf("%d",&n); scanf("%s",beads); for (int i=0;i<n;i++) { beads[i+n]=be
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1818自1900年以来所有的13日的星期数统计题目的输出貌似有误:七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一.....星期五的次数.实际情况的输出是从周一到周日依次输出。思路:我的做法比较朴素...把所有的天数遍历一遍。还好数据无误。#include<stdio.h>int ans[7]={0};int date=1,day=1;int main(){ int n; int leap; scanf("%d",&n); for(int i=0;i
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1817几个人互相送钱,问最后每个人收取的比送出的多多少又在数据初始化的问题上搞了半天#include<stdio.h>#include<string.h>struct person{ char name[15]; int money; int give; int get;}f[11];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s",f[i]
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1816经过计算对比两组数据 注意数据范围是long long#include<stdio.h>int main(){ char ufo[10]; char group[10]; long long ufon=1; long long groupn=1; scanf("%s",ufo); scanf("%s",group); for(int i=0;ufo[i]!='\0';i++) { ufon*=ufo[i]-'A'+1
阅读全文
摘要:高中同学问了我一道题,开始以为简单循环就能完成,后来发现原来是道深搜题,一开始还没想出来...问题描述给1到N,N个数,要你从中选取M个出来,请输出每一种的选取情况(根据序列字典序输出,即两个序列比大小,第一位小的小,若相等第二位小的小,若相等第三位小的小……)。 样例输入4 3样例输出1 2 3 1 2 4 1 3 4 2 3 4#include<stdio.h>int ans[10];void dfs(int start,int has,int n,int m){ if(has==m) { for(int i=0;i<m;i++)printf("%d "
阅读全文
摘要:题目:http://poj.org/problem?id=2593这题和2479除了输入方式和数据范围不同以外没看出来还有什么不同#include <stdio.h>int dp1[100005],dp2[100005];int arr[100005];int main(){ while (1) { int n; scanf("%d",&n); if(n==0) break; scanf("%d",&arr[0]); dp1[0]=arr[0]; for(int i=1;i<n;i++) ...
阅读全文
摘要:题目:http://poj.org/problem?id=2479思路:动态规划 求两段最长子段的和 对每个i来说,求出[0~i-1]的最大子段和以及[i~n-1]的最大子段和,再相加起来,求最大的一个。#include <stdio.h>int dp1[50005],dp2[50005];int arr[50005];int main(){ int T; scanf("%d",&T); while (T--) { int n; scanf("%d",&n); scanf("%d",&arr[0])
阅读全文
浙公网安备 33010602011771号