随笔分类 - ACM--暑假多校联合
摘要:03 hdu5009状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数。普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色、三种、四种。。。o[]种的位置。离散化之后,可以...
阅读全文
摘要:hdu4911max(逆序数-k,0) 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 #defin...
阅读全文
摘要:1006hdu4902 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define LL long long 10 #d...
阅读全文
摘要:A hdu4861打表找规律 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define eps 1e-4 9 #define zero(x) ((fabs(x...
阅读全文
摘要:链接这题可以算树形DP吧 树上的递推对于树上的某个节点 反着算比较好做 就是算有多少有simple路径的固定某个节点u 另两个节点 有两种取法1.从不同子树里各选一个2.从所有子树里选一个 再从以u为跟的子树 外面选一个求总和 1 #pragma comment(linker, "/STACK:16777216") 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 100010 9 #define LL __int6410 struct node
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4681枚举A串和B串包含C串的区间 枚举区间端点算左右两端最长公共子序 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 1010 8 char s1[N],s2[N],s3[N]; 9 int dp1[N][N],dp2[N][N];10 struct node11 {12 int l,r;13 }p1[N],p2[N];14 int main()15 {16 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4678之前写了一并差集找连通块 貌似不对 比赛时写的dfs爆栈了 只好用bfs了单独数字块 为1空白+数字块 数字数%2+1异或 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 1010 9 int dis[8][2] = {1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};10 int n,m,k;11 int vis[N][.
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4669这题各种错误都来了一遍 预处理一下第一个数作为尾数与相邻前面的数组成的数的余数 然后再与后面的结合求余数9 6 4 2 8 因为是个环 可以 9 6 4 2 8 9 6 4 2 8 组合 不过 又不能超N所以先预处理 89 289 4289 64289 的余数 再与后面的组合 删除重复的 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define N 50005 7 #define LL __int64 8 .
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4632TLE了N次 原因居然是取模次数太多了。。! 这数据卡的好紧 还是我写的太搓。。828ms挤过s[i]==s[j]dp[i][j] = dp[i][j-1]+dp[i+1][j]+1;else dp[i][j] = dp[i][j-1]+d[[i+1][j]-dp[i+1][j-1]; 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define mod 10007 7 char s[1010]; 8 int .
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4671这个高端的题意啊 看了N久啊n>m时 直接第一列按顺序来 第二列为M+1else 第一列顺序来 第二列 按第一组为N 第二组为N-1 依次分配 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 110 8 int f[110][110],a[110][110],x[110]; 9 int main()10 {11 int i,j,k,n,m;12 while...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4666先看一个求曼哈顿的帖子http://www.cnblogs.com/lmnx/articles/2479747.html然后用mulityset进行维护下就可以了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define N 60010 9 int w[N][10];10 int main()11 {12 int i,j,q,g,k;13 whil...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4293这题单拉出来写篇吧 确实不错的一题将每个人说的话 转化一下 可以算出它处在哪个段中 题目就转换成了求不相交的最大段数 注意区间相同的情况 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 struct node 8 { 9 int l,r;10 }p[510];11 int dp[510],w[510][510];12 bool cmp(node a,node b)13 {14 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4655先以最大的来算为 N*所有的排列数 再减掉重复的 重复的计算方法:取相邻的两个数的最小值再与它前面的组合数和后面的组合数相乘注意负值 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define LL long long 8 #define N 1000100 9 #define mod 100000000710 LL s1[N],s2[N],a[N],b[N];11 int main().
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4662I+3*U模6为2或4的都可以 一个U相当于3个I 而I只能1-》2-》4-》8。。如此变换 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 char s[100010]; 7 int main() 8 { 9 int i,n;10 cin>>n;11 while(n--)12 {13 cin>>s;int a=0,b=0;14 int k = st...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4648求连续的一段和对m取余为0 若s[j]和s[i]对M的余数都相同 则相见就满足要求 找个最长的 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define LL long long 8 #define N 100010 9 #define INF 0xfffffff10 LL s[N];11 int a[N],d1[N],d2[N];12 int main()13 {14 int...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4647很扯的一题 将每条边的一半权值分给它所连的两个结点 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 double a[100010]; 8 int main() 9 {10 int i,j,n,m,u,v;11 while(cin>>n>>m)12 {13 for(i = 1; i >a[i];15 double s;16 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4639统计连续he的数量恰为斐波序列 不同块进行相乘 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define mod 10007 7 using namespace std; 8 char ss[11000]; 9 int f[11000];10 int main()11 {12 int t,i,k,kk=0;13 cin>>t;14 f[1] = 1;f[2] = 2;15 for(i = 3; i ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4638求某一区间所包含的连续的段 对于乱序的数 到了i这个数所包含的段数 首先把这个数看作单独的段 再看一下前面是否出现了它的朋友 若出现了就说明前面已经加过这样单独的段了 就把前面的更新掉-1 这样始终保证一个段的最后一个值记录着这是第几个段 从左到右扫描一遍 离线处理后 这样用树状数组或者线段树进行区间求和就可以了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define N 100010 7 using namespace std.
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4635tarjan缩点 统计缩点后每个结点的出度入度 将那个包含原来点数最少的 且出度或者入度为0的大节点看作一个整体内部连边n*(n-1)个 连全部的; 其它的点为一整体连全部的 再两者连一同向的边 保证它的出度或者入度依旧为0的情况下任意连 最后减去原来的边M 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 100010 8 #define M 100010...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4642这题。。刚一看以为是什么高深的博弈 后来看过的人挺多 想是不是有什么规律 结果理解错题意了 以为随便圈一矩形改变就可以 然后想了一方法 跟QC说 然后就知道自己理解错题意了 必须圈到右下角 然后就乱了 后来QC说感觉只要右下角是1她就赢了 一想确实是这样啊 。。好简单 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int a[110][110]; 7 int main() 8 { 9 int i,j,t...
阅读全文