双指针. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; +; long long a[maxn]; in…
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken o…
题意: 输入一个正整数N和M(N<=1e5,M<=1e8),接下来输入N个正整数(<=1e3),按照升序输出"i-j",i~j的和等于M或者是最小的大于M的数段. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; vector<pair<int,int> >ans; int main()…
1044 Shopping in Mars (25 分)   Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and s…
题目 Shopping in Mars is quite a diferent experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken…
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken o…
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken o…
n,m然后给出n个数让你求所有存在的区间[l,r],使得a[l]~a[r]的和为m并且按l的大小顺序输出对应区间.如果不存在和为m的区间段,则输出a[l]~a[r]-m最小的区间段方案. 如果两层for循环l和r的话,会超时,实际上for循环一遍即可. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <vector> #…
分析: 考察二分,简单模拟会超时,优化后时间正好,但二分速度快些,注意以下几点: (1):如果一个序列D1 ... Dn,如果我们计算Di到Dj的和, 那么我们可以计算D1到Dj的和sum1,D1到Di的和sum2, 然后结果就是sum1 - sum2: (2): 那么我们二分则要搜索的就是m + sum[i]的值. #include <iostream> #include <stdio.h> #include <algorithm> #include <cstr…
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; +]; ,sum2; int n; int main() { scanf("%d&q…
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n,root; ; struct Node { int left…
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; ; int n,m; vector<int>g[maxn]; int ans[…
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; +; struct Node { ]; ]; ]…
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<string> #include<stack> #include<map> #include<algorithm> using namespace std; struct X { int id;…
模拟题.坑点较多. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace…
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace std…
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace std;…
暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; int ans,len,sum; void check(int a,int b) { if(s[a]!=s[b]) return; ; ; ,right=b+; ||right>=len||s[left]!=s[right])) left--,right++,sum=sum+; ans=max(ans…
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; void pri(int a) { ) printf("%d", a); +'A'); } void print(int a){ ) { pri(a/); pri(a%);} "); pri(a); } } int main() { in…
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> using namespace std; struct X { long long hh,mm,ss; long long len; long long st,ml; }s[…
并查集判断连通性. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> using namespace std; ; struct Edge { int u,v; }e[maxn*maxn]; int n,m,k; int f[maxn]; int Find(int x) { if…
简单排序题. 注意:分数相同的人排名相同. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> using namespace std; struct X { int k; int id; int f1,f2,f3,f4; ]; }s[]; int n,m; map<int,…
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; ],b[],c[]; int k; int main() { ;i<=;i++) a[i]=b[i]=c[i]=; ; scanf("%d",&k); ;i<=k;i++) {…
简单DP. 注意:If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence. #include<iostream> #include<cstring> #include<cmath> #include<al…
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For examp…
简单题.模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; ; int a[maxn],b[maxn],n; int main() { sc…
入栈顺序为先序遍历,出栈顺序为中序遍历. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<stack> using namespace std; +; const int INF=0x7FFFFFFF; int n,tot; int Preorder[maxn],Inorder[maxn],Postorder[maxn]; int AP…
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<vector> using namespace std; ; struct X { string name; string sex; string…
Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two integers N (≤) and C, where N is the number of reco…
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are…