题目描述: 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源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前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…
问题描述: 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"…
题目描述: 源码: 需要注意,若使用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"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"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…
题目描述: 源码: 需要注意的一点是输出是最简形式,需要去除小数的后导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…
题目描述: 源码: 运用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 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" #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" 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" #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…
题目描述: 源码: /**/ #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…
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…
ACM,算法 描述 最近Topcoder的XD遇到了一个难题,倘若一个数的三次方的后三位是111,他把这样的数称为小光棍数.他已经知道了第一个小光棍数是471,471的三次方是104487111,现在他想知道第m(m<=10000000000)个小光棍数是多少?   输入 有多组测试数据.第一行一个整数n,表示有n组测试数据.接下来的每行有一个整数m. 输出 输出第m个小光棍数. 样例输入 1 1 样例输出 471 #include <iostream> #include <str…
ACM算法模板 · 一些常用的算法模板-模板合集(打比赛专用)…
数据结构与算法入门系列教程 (一)为啥要学习数据结构与算法 曾经我也以为自己很牛逼,工作中同事也觉得我还可以,领导也看得起我,啥啥啥都好,就这样过了几年,忽然发现自己学新东西没劲.时代都变了,而我还只是会写一些简单的业务代码,每天也只是复制来复制去的. 是时候改变了,所以这就是我来学习这些东西的原因. (二)Demo地址 C#的Demo,github地址如下:  https://github.com/gdoujkzz/DataStructureForCSharp (三)教程目录 入门不容易->先…
动态规划 1.背包问题 (1)01背包 ,n) DFR(v,V,C[i]) F[v]=max(F[v],F[v-C[i]]+W[i]); } //初始化时 //若背包不一定装满F全初始化为0 //若装满 F[0]=0 其他为-inf   (2)全然背包 ,n) FOR(v,C[i],V) {F[v]=max(F[v],F[v-C[i]]+W[i]);} } (3)多重背包 ; ZeroOnePack(C[i]*M[i],W{i]*M[i]) } }   //O(VN) 单调队列? ? (4)多重…
一:知识点 数据结构: 1,单,双链表及循环链表 2,树的表示与存储,二叉树(概念,遍历)二叉树的 应用(二叉排序树,判定树,博弈树,解答树等) 3,文件操作(从文本文件中读入数据并输出到文本文 件中) 4,图(基本概念,存储结构,图的运算) 数学知识 1,离散数学知识的应用(如排列组合.简单的图论,数理逻辑) 2,数论知识 3,线性代数 4,组合代数 5,计算几何 二 算法 1,排序算法(冒抛法,插入排序,合并排序,快速排序,堆排序) 2,查找(顺序查找,二分发) 3,回溯算法 4,递归算法…