题目描述: 源码: 需要注意的一点是输出是最简形式,需要去除小数的后导0,而调用stripTrailingZeros()函数后,数会以科学计数法输出,所以需要调用toPlainString(). import java.math.BigDecimal; import java.util.*; public class Main { //主函数 public static void main(String[] args) { BigDecimal a, b; Scanner cin = new S…
题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的那一瞬间,实际将要占用的空间应该为A1+B2,那么为了保证留下的空间最大,则应该有A1+B2<A2+B1成立,才能先搬运A1,即B1-A1>B2-B1.(n个设备可以两两做这样的比较,来达到选择的最优) #include"iostream" #include"algo…
题目描述: AC源码: 此题考查贪心算法,解题思路:首先使用快速排序,以w或l按升序排序(注意相等时,应按另一值升序排序),这样就将二维变量比较,变为了一维的,排好序的一边就不需要去管了,只需要对未排序的一边直接进行贪心遍历.时间复杂度O(n^2) #include"iostream" #include"algorithm" using namespace std; struct Stick { int l; int w; bool processed; }; bo…
问题描述: AC源码: 解题关键是,数据很大,不能强算,需要使用技巧,这里使用科学计算法,令N^N=a*10^n ,取对数后变为 N*log10(N)=log10(a)+n,令x = log10(a)+n  又 n = int(x)  [取整,当然根据所给数据范围,为了避免溢出,这是使用的是long long取整],则 a = 10^(x - int(x)),最后带入x= N*log10(N),对a的值取整即为最终结果. #include"iostream" #include"…
题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstHalf(string *strs, int n, string str) { int count = 0; for(int i = 0; i < n; i++) { if(str < strs[i])count++; } return count >= (n / 2 + n % 2); }…
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorithm" #include"string" using namespace std; struct Person { string name; int count; int score; }; bool cmp(Person a, Person b) { if(a.count >…
题目描述: 源码: #include"iostream" #include"string" using namespace std; void Order(int *p, int n) { int tmp; if(n < 2)return; for(int i = 0; i < n - 1; i++) { for(int j = 0; j < n - i - 1; j++) { if(p[j] > p[j + 1]) { tmp = p[j]…
题目描述: 源码: #include"iostream" using namespace std; int main() { int n, digit, carry, tmp; int a[40000]; while(cin>>n) { if(n <= 1) { cout<<1<<endl; } else { a[0] = 1; digit = 1; for(int i = 2; i <= n; i++) { carry = 0; for…
题目描述: 源码: /**/ #include"iostream" using namespace std; int main() { int t, mod; long long n; cin>>t; for(int i = 0; i < t; i++) { cin>>n; mod = n % 10; if(mod == 0 || mod == 1 || mod == 5 || mod == 6) { cout<<mod<<endl…
题目描述: 源码: #include <cstdio> #include <ctime> int main() { int year, month, day; int sum; while(scanf("%d/%d/%d", &year, &month, &day) != EOF) { sum = day; for(int i = 1; i < month; i++) { if(i == 1 || i == 3 || i == 5…
问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于第i+1个的值) #include"iostream" using namespace std; int main() { int t, n, start, end, sum, max, tmp; int a[100000]; scanf("%d", &t);…
问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int main() { int t, n, sq, sum; scanf("%d", &t); for(int i = 0; i < t; i++) { scanf("%d", &n); sum = 1; sq = (int)sqrt(n); for(int…
题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #define MAX 1000000 using namespace std; int index[MAX]; int main() { memset(index, -1, sizeof(index)); index[1] = 0; int sum = 0; for(int i = 2; i < MAX; i++…
问题描述: 源码: 经典问题——最近邻问题,标准解法 #include"iostream" #include"algorithm" #include"cmath" using namespace std; struct Point { double x; double y; }; Point S[100000];//不使用全局变量可能会超内存 bool cmpPointX(Point a, Point b) { return a.x > b…
问题描述: 源码: #include"iostream" #include"algorithm" using namespace std; bool cmp(int a, int b) { return a < b; } int main() { int n, result; int *p; while(true) { scanf("%d", &n); if(n == 0)break; p = new int[n]; for(int…
问题描述: 源码: import java.math.BigInteger; import java.util.*; public class Main { //主函数 public static void main(String[] args) { BigInteger a, b, zero = BigInteger.valueOf(0), f1, f2, fn; int count; Scanner cin = new Scanner(System.in); while(true) { a…
问题描述: 源码: import java.math.BigInteger; import java.util.*; public class Main { //主函数 public static void main(String[] args) { int n; BigInteger a, result, zero = BigInteger.valueOf(0); Scanner cin = new Scanner(System.in); n = cin.nextInt(); for(int…
问题描述: 源码: 考察对大数的计算,需要注意去除前导0与后导0. import java.math.BigDecimal; import java.util.*; public class Main { //主函数 public static void main(String[] args) { BigDecimal r; int n; String str; Scanner cin = new Scanner(System.in); while(cin.hasNext()) { r = ci…
题目描述: 源码: 运用Java大数求解. import java.math.BigInteger; import java.util.*; public class Main { //主函数 public static void main(String[] args) { int n, index; BigInteger f1, f2, fn; Scanner cin = new Scanner(System.in); n = cin.nextInt(); for(int i = 0; i <…
问题描述: 源码: /**/ #include"iostream" #include"string" using namespace std; void Print(string str, int end, int start) { for(int i = end; i >= start; i--)cout<<str[i]; } int main() { int n, start, end; string str; while(cin>>…
题目描述: 源码: #include"iostream" #include"cmath" using namespace std; #define PI 3.1415926 #define E 2.718281828459045 int main() { int n, num; double sum; cin>>n; for(int i = 0; i < n; i++) { cin>>num; // sum = 0; // for(in…
题目描述: 源码: /**/ #include"iostream" #include"string" using namespace std; string Standard(string str) { int start; int len = str.length(); char * p = new char[len + 2]; start = 0; if(str[0] == '-' || str[0] == '+') { p[0] = str[0]; start…
题目描述: 源码: /**/ #include"iostream" using namespace std; int MinComMultiple(int n, int m) { int x, y, tmp; long long s; s = (long long)n * (long long)m;//避免int的乘积越界 if(n > m) { tmp = n; n = m; m = tmp; } tmp = m % n; while(tmp != 0) { m = n; n…
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java 集合系列 04 LinkedList详细介绍(源码解析)和使用示例 Java 集合系列 05 Vector详细介绍(源码解析)和使用示例 Java 集合系列 06 Stack详细介绍(源码解析)和使用示例 Java 集合系列 07 List总结(LinkedList, ArrayList等使用场景和…
July   二零一一年一月 本文主要参考:算法导论 第二版.维基百科. 一.Dijkstra 算法的介绍 Dijkstra 算法,又叫迪科斯彻算法(Dijkstra),算法解决的是有向图中单个源点到其他顶点的最短路径问题.举例来说,如果图中的顶点表示城市,而边上的权重表示著城市间开车行经的距离,Dijkstra 算法可以用来找到两个城市之间的最短路径. 二.图文解析 Dijkstra 算法 ok,经过上文有点繁杂的信息,你还并不对此算法了如指掌,清晰透彻.没关系,咱们来幅图,就好了.请允许我再…
Newtonsoft.Json C# Json序列化和反序列化工具的使用.类型方法大全   Newtonsoft.Json Newtonsoft.Json 是.Net平台操作Json的工具,他的介绍就不多说了,笔者最近在弄接口,需要操作Json. 以某个云计算平台的Token为例,边操作边讲解. Json 转为 Model 将 Model 转为 Json 将 LINQ 转为 JSON Linq 操作 命名空间.类型.方法大全 另外附上 百度AI 文字识别 Json 及其模型类 Newtonsof…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3791 中文题不说题意. 建立完二叉搜索树后进行前序遍历或者后序遍历判断是否一样就可以了. 跟这次的作业第一题一模一样,输出输入改下就好 水的半死. 另外一题我以为是一定要一遍读入一边输出,被骗了,最后一起输出就好.等星期一再发那题的题解. #include<cstdio> #include<cstring> int cur; struct node { char c; node *lef…
算法复杂度主方法 有时候,我们要评估一个算法的复杂度,但是算法被分散为几个递归的子问题,这样评估起来很难,有一个数学公式可以很快地评估出来. 一.复杂度主方法 主方法,也可以叫主定理.对于那些用分治法,有递推关系式的算法,可以很快求出其复杂度. 定义如下: 如果对证明感兴趣的可以翻阅书籍:<算法导论>.如果觉得太难思考,可以跳过该节. 由于主定理的公式十分复杂,所以这里有一种比较简化的版本来计算: 二.举例 二分搜索,每次问题规模减半,只查一个数,递推过程之外的查找复杂度为O(1),递推运算时…
概要 这一章,我们对HashMap进行学习.我们先对HashMap有个整体认识,然后再学习它的源码,最后再通过实例来学会使用HashMap.内容包括:第1部分 HashMap介绍第2部分 HashMap数据结构第3部分 HashMap源码解析(基于JDK1.6.0_45)第3.1部分 HashMap的“拉链法”相关内容第3.2部分 HashMap的构造函数第3.3部分 HashMap的主要对外接口第3.4部分 HashMap实现的Cloneable接口第3.5部分 HashMap实现的Seria…
快速开发系列 10个常用工具类 http://blog.csdn.net/lmj623565791/article/details/38965311 ------------------------------------------------------------------------------------------------ 不知众多Android开发者是否在程序开发的工程中也遇到过下面的问题: 0.如何在众多log中快速找到你设置打印的那行log? 1.是否还在不断的切换标签来…