问题描述: 源码: /**/ #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>>…
题目描述: 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…