08 2013 档案
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1730分析:线段树单点更新,区间求和。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 500005 7 #define mod 1000007 8 using namespace std; 9 int sum[maxn>1;19 build(l,m,rt>1;30 if(ii>1;38 int res=0;39 if(L=m+1)res^=get_sum(L,R,m+1,r,rt...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1727分析:用 l[i] 记录第 i 层楼有多少物品需要往上继续搬运,如果某层楼没有物品,但是更上面还有,则仍需要往上走,所以需要+1. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 111 7 #define mod 1000007 8 using namespace std; 9 int l[maxn];10 int main()11 {12 int n,cas=1,s,t,rig;13 w...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1732分析:dp,n个相同物品放入m个相同的盒子(允许为空)的个数为dp[n][m]=dp[n][m-1]+dp[n-m][m];dp[n][m-1]表示有空盒的情况,dp[n-m][m]表示没有空盒的情况。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 101 7 #define mod 1000007 8 using namespace std; 9 int dp[maxn][maxn];10 void s
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2722分析:简单最短路,读入数据烦。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define maxn 450 9 #define inf 0xfffffff10 using namespace std;11 int blip[maxn];12 int n,m;13 bool vis[maxn];14 struct edge15 {16 int to,w;17 edg...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2363分析:最短路+二分。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define ll long long 10 #define maxn 105 11 #define inf 0x7fffffff 12 using namespace std; 13 int T,n,m,low,up; 14 int h[maxn],map[maxn][ma...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962分析:最短路+二分。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #define ll long long11 #define inf 100000000012 #define maxn 100513 using namespace std;14 struct edge15 {16 int to,h,len;17 edg...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217分析:floyd. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #define ll long long11 #define maxn 3312 #define inf 0xfffffff13 using namespace std;14 int n;char cur[30];15 mapm;16 double mapp[maxn][ma
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1142分析:最短路+记忆化搜索。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0x6fffffff10 #define maxn 100511 using namespace std;12 struct edge13 {14 int to,time;15 edge(int x,int y)16 ...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874分析:SPFA|Dijkastra. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0x6fffffff10 #define maxn 20511 using namespace std;12 int g[maxn][maxn],dis[maxn],n,m;13 bool vis[maxn];14 void dij
阅读全文
摘要:原题连接:http://acm.hdu.edu.cn/showproblem.php?pid=2066分析:超级源点+SPFA。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0xfffffff10 #define maxn 100511 using namespace std;12 struct edge13 {14 int to,time;15 edge (int x,int y)16 ...
阅读全文
摘要:原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1267分析:此题麻烦之处在于要输出最小最长上升子序列,关键在于如何解决最小这个问题.我的做法是从最后一个数开始往前扫描,同时另开一重循环,从该数num[i]前一个往前扫描,即j=i-1~0.如果num[j] 2 using namespace std; 3 int num[1005]; 4 int dp[1005]; 5 int nxt[1005]; 6 int main() 7 { 8 int T; 9 scanf("%d",&T);10 while(T--)11
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394分析:树状数组的应用。Minimum Inversion Number 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 5005 7 using namespace std; 8 int c[maxn],num[maxn],n; 9 int low_bit(int i)10 {11 return i&(-i);12 }13 void update(int i,int v)14 {15 w...
阅读全文
摘要:求逆序数的方法有很多,比如归并排序,但本文重点讲一下如何用树状数组来求逆序数。 当数据的范围较小时,比如maxn=100000,那么我们可以开一个数组c[maxn],来记录前面数据的出现情况,初始化为0;当数据a出现时,就令c[a]=1。这样的话, 欲求某个数a的逆序数,只需要算出在当前状态下c[a+1,maxn]中有多少个1,因为这些位置的数在a之前出现且比a大。但是若每添加一个数据a时,就得从a+1到 maxn搜一遍,复杂度太高了。树状数组却能很好的解决这个问题,同样开一个数组d[maxn],初始化为0,d[i]记录下i结点所管辖范围内当前状态有多少个数;当添加数 ...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003分析:定义dp[i][1]表示到第i个数时的最大连续和,dp[i][1]表示dp[i][0]取到最大值时的左边起始位。Max Sum 1 #include 2 #include 3 #include 4 #include 5 #define maxn 100005 6 using namespace std; 7 int num[maxn],dp[maxn][2]; 8 int main() 9 {10 int T,cas=1;11 scanf("%d",&T);1
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010分析:dfs+奇偶剪枝。Tempter of the Bone 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 char s[10][10]; 7 bool visit[10][10],flag; 8 int dx[4]={0,0,1,-1}; 9 int dy[4]={-1,1,0,0};10 int n,m,t,di,dj;11 void dfs(int time,int i,int j)12 {13
阅读全文
摘要:原题链接:http://poj.org/problem?id=2488分析:如果存在合法路径,那么一定可以将路径的起始点定为(A,1),从该点按字典序DFS,如果找到一条路径,那么这条路即为所求。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 27 6 using namespace std; 7 int dirx[8]={-2,-2,-1,-1,1,1,2,2}; 8 int diry[8]={-1,1,-2,2,-2,2,-1,1}; 9 char path[maxn0&&ny>0&&am
阅读全文
摘要:原题链接:http://poj.org/problem?id=2406分析:求最小周期。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1000005 6 using namespace std; 7 char s[maxn]; 8 int next[maxn],len; 9 void get_next()10 {11 int i=0,j=-1;len=strlen(s);12 next[0]=-1;13 while(i<len)14 {15 if(j==-1||s[i]==...
阅读全文
摘要:原题链接:http://poj.org/problem?id=2752分析:no! 1 #include 2 #include 3 #include 4 #define maxn 400005 5 using namespace std; 6 char s[maxn]; 7 int len,next[maxn],ans[maxn]; 8 void get_next() 9 {10 int i=0,j=-1;len=strlen(s);11 next[0]=-1;12 while(i=1;j--)31 printf("%d ",ans[j]);32 ...
阅读全文
摘要:原题链接:http://poj.org/problem?id=3461分析:求一个串在另一个串中出现的次数,显然用KMP可以解决。 1 #include 2 #include 3 #include 4 #define maxn1 10005 5 #define maxn2 1000005 6 using namespace std; 7 char s[maxn1],t[maxn2]; 8 int next[maxn1],sum,len1,len2; 9 void get_next()10 {11 int i,j;len1=strlen(s);12 next[0]=-1;13 ...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1404分析:定义dp[i][j]表示i位时最左边为j时的情况,那么dp[i][[j]可以由dp[i-1][k](k>=j)得到。Non-Decreasing Digits#include#include#include#include#define maxn 100005#define ll long longusing namespace std;ll dp[70][12];void solve(){ for(int i=0;i=0;j--) { dp[i][j]=sum+dp[i-1][j];
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problems.php?vol=15分析:首先筛出sqrt(2^31-1)以内的素数,对于给定的区间[L,R],仍然用筛素数的思想把那些是前面筛选出来的素数的倍数的做标记,然后从左到右扫一遍即可。How many primes 1 #include 2 #include 3 #include 4 #include 5 #define maxn 100005 6 using namespace std; 7 int prime[maxn],t; 8 bool ans[1000005]; 9 bool flag[maxn]={false}
阅读全文

浙公网安备 33010602011771号