摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2553 1 #include 2 #include 3 using namespace std; 4 5 int n,tot,x[15]; 6 7 void dfs(int t){ 8 if(t>n) tot++; 9 else{10 for(int i=1;i>n,n) cout<<a[n]<<endl;32 return 0;33 }
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176解题思路:核心为 dp[x][T]=dp[x][T]+max(dp[x-1][T+1],dp[x][T+1],dp[x+1][T+1]), 其中 1≤x≤11, 0≤T 2 #include 3 using namespace std; 4 5 int dp[15][100005]; 6 7 int max(int x,int y,int z){ 8 if(y>x) x=y; 9 if(z>x) x=z;10 return x;11 }12 13 int main(...
阅读全文
摘要:题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=14解题思路:按活动结束时间从小到大排序,优先选择小的,显然,第一个活动一定被选,按顺序依次判断下一个活动的开始时间是否大于当前被选的最后一个活动的结束时间,若是,选之,否则,跳过。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct T{ 7 int Bi,Ei; 8 bool operator Max){23 num++;24 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575解题思路:矩阵快速幂 1 #include 2 using namespace std; 3 4 int n; //nxn矩阵 5 6 struct Matrix{ 7 int a[10][10]; 8 }origin,res; 9 10 Matrix multiply(Matrix x,Matrix y){11 Matrix temp;12 for(int i=0;i>=1;26 origin=multiply(origin,origin);27...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1163解题思路:核心为 a[i-1][j]=a[i-1][j]+max(a[i][j],a[i][j+1]), 其中 1 2 using namespace std; 3 4 int main(){ 5 int n,i,j,a[101][101]; 6 cin>>n; 7 for(i=1;i>a[i][j]; 9 }10 for(i=n;i>1;i--){11 for(j=1;ja[i][j+1]? a[i][j]:a[i][j+1]);13 }14 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2157解题思路:矩阵快速幂 1 #include 2 using namespace std; 3 4 int n; //n个点,对应nxn矩阵 5 6 struct Matrix{ 7 int a[20][20]; 8 }res; 9 10 Matrix multiply(Matrix x,Matrix y){11 Matrix temp;12 for(int i=0;i>=1;26 origin=multiply(origin,origin);27 ...
阅读全文
摘要:一、输入(主要是使用Scanner类)1、导入Scanner类:import java.util.Scanner;2、创建Scanner类的对象:Scanner cin=new Scanner(System.in);3、使用Scanner类的对象读入各种类型的数据:①读入数据(常用)读一个整数:int n=cin.nextInt(); 【C:scanf("%d",&n); 】 【C++:cin>>n;】读一个字符串:String s=cin.next(); 【C:scanf("%s",s); 】 【C++:cin>>s;
阅读全文
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=406解题思路:最小生成树(kruskal 算法 + 优先队列 + 并查集) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: zoj 1406 4 problem_name: Jungle Roads 5 *********************************...
阅读全文
摘要:java.math包中的BigInteger类和BigDecimal类分别提供任意精度的整数和小数运算。1、BigInteger类①导入:import java.math.BigInteger;②常用方法:BigInteger valueOf(long val) 【转换】int compareTo(BigInteger val) 【返回值1、0、-1分别表示大于、等于、小于】BigInteger add(BigInteger augend) 【加法】BigInteger subtract(BigInteger subtrahend) 【减法】BigInteger multiply(BigInt
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009解题思路:按单位 cat food 所能换取的 JavaBeans 量(即 J[i]/F[i] )从大到小排序,优先选择比值大的进行交换,直到消耗完 cat food 。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct Trade{ 7 int J,F; 8 double C; 9 bool operator t.C;11 }12 }T[1005];13 14 int mai...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=42591. n张牌 (1,2,···,n) 按顺序发给k个人,再把牌收回,第1个人的放最上面,后面的依次放下面。继续发牌,收牌,问多少次后恢复原样。2. 以 n=10,k=3 为例,4次后牌的次序恢复原样,如下:第一次: 10 7 4 1 8 5 2 9 6 3第二次: 3 2 1 10 9 8 7 6 5 4第三次: 4 7 10 3 6 9 2 5 8 1第四次: 1 2 3 4 5 6 7 8 9 103. 经过 1 次操作(发牌+收牌)后,下标变化情况如下:原次
阅读全文
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=18361. 设 n, k 都是正整数,S={1,2,···,n}, 则 S 中能被 k 整除的正整数的个数为 [n/k].2. 设 Ai(i=1,2,···,n) 为有限集,则.3. lcm(x,y)=xy/gcd(x,y).4. lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn).5. 对于输入数据 N,M
阅读全文
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=372解题思路:最小生成树(kruskal 算法 + 优先队列 + 并查集) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: zoj 1372 4 problem_name: Networking 5 ***********************************...
阅读全文