官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/

表示很难看。。。。orz

1003题      链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355

Cake

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1138    Accepted Submission(s):
152
Special Judge

Problem Description
There are m soda
and today is their birthday. The 1-st
soda has prepared n cakes
with size 1,2,…,n.
Now 1-st
soda wants to divide the cakes into m parts
so that the total size of each part is equal.

Note that you
cannot divide a whole cake into small pieces that is each cake must be complete
in the m parts.
Each cake must belong to exact one of m parts.

 
Input
There are multiple test cases. The first line of input
contains an integer T,
indicating the number of test cases. For each test case:

The first
contains two integers n and m (1≤n≤105,2≤m≤10),
the number of cakes and the number of soda.
It is guaranteed that the total
number of soda in the input doesn’t exceed 1000000. The number of test cases in
the input doesn’t exceed 1000.

 
Output
For each test case, output "YES" (without the quotes)
if it is possible, otherwise output "NO" in the first line.

If it is
possible, then output m lines
denoting the m parts.
The first number si of i-th
line is the number of cakes in i-th
part. Then si numbers
follow denoting the size of cakes in i-th
part. If there are multiple solutions, print any of them.

 
Sample Input
4
1 2
5 3
5 2
9 3
 
Sample Output
NO
YES
1 5
2 1 4
2 2 3
NO
YES
3 1 5 9
3 2 6 7
3 3 4 8
 
Source
 

题意:n块蛋糕(大小1--n)分给m个人,要求每个人得到蛋糕大小总和相等

  1.  
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = + ;
  5. int ret[][MAXN];
  6. int vis[], a[];
  7. int tot, tar;
  8.  
  9. bool dfs(int dep, int now, int u, int c)
  10. {
  11. if (now == )
  12. {
  13. int k = ;
  14. while (vis[k] != -) ++ k;
  15. vis[k] = c;
  16. if (dfs(dep + , a[k], k + , c)) return true;
  17. vis[k] = -;
  18. return false;
  19. }
  20. if (now == tar)
  21. {
  22. if (dep == tot) return true;
  23. else return dfs(dep, , , c + );
  24. }
  25. for (int i = u; i < tot; ++ i)
  26. {
  27. if (vis[i] == - && now + a[i] <= tar)
  28. {
  29. vis[i] = c;
  30. if (dfs(dep + , now + a[i], i + , c)) return true;
  31. vis[i] = -;
  32. }
  33. }
  34. return false;
  35. }
  36.  
  37. int main()
  38. {
  39. int T;
  40. scanf("%d", &T);
  41. for (int cas = ; cas <= T; ++ cas)
  42. {
  43. int n, k;
  44. scanf("%d%d", &n, &k);
  45. //fprintf(stderr, "%d %d\n", n, k);
  46. LL sum = (LL)n * (n + ) / ;
  47. if (sum % k == && n >= k * - )
  48. {
  49. while (n >= )
  50. {
  51. for (int i = ; i < k; ++ i) ret[i][++ ret[i][]] = n - i;
  52. for (int i = ; i < k; ++ i) ret[i][++ ret[i][]] = n - k * + i + ;
  53. n -= k * ;
  54. }
  55. tot = n;
  56. tar = n * (n + ) / / k;
  57. for (int i = ; i < tot; ++ i) a[i] = tot - i;
  58. for (int i = ; i < tot; ++ i) vis[i] = -;
  59. dfs(, , , );
  60. for (int i = ; i < tot; ++ i)
  61. {
  62. ret[vis[i]][++ ret[vis[i]][]] = a[i];
  63. }
  64. for (int i = ; i < k; ++ i)
  65. {
  66. printf("%d ", ret[i][]);
  67. for (int j = ; j <= ret[i][]; ++ j) printf(" %d", ret[i][j]);
  68. puts("");
  69. }
  70. }
  71. else puts("NO");
  72. }
  73. return ;
  74. }

1006题          链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358

First One

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072
K (Java/Others)
Total Submission(s): 757    Accepted Submission(s):
230

Problem Description
soda has an integer array a1,a2,…,an.
Let S(i,j) be
the sum of ai,ai+1,…,aj.
Now soda wants to know the value below:

∑i=1n∑j=in(⌊log2S(i,j)⌋+1)×(i+j)

Note:
In this problem, you can consider log20 as
0.

 
Input
There are multiple test cases. The first line of input
contains an integer T,
indicating the number of test cases. For each test case:

The first line
contains an integer n (1≤n≤105),
the number of integers in the array.
The next line
contains n integers a1,a2,…,an (0≤ai≤105).

 
Output
For each test case, output the value.
 
Sample Input
1
2
1 1
 
Sample Output
12
 
Source
 

题意:求

思路:利用S(i,j)单调性,     log2(S(i,j))+1= k
=2^(k-1)<= S(i,j)<2^k

考虑枚举log(sum(i,j)+1的值,记为k,然后统计(i+j)的和即可。

对于每一个k,找到所有满足2^(k-1)<=sum(i,j)<=2^k-1的(i+j),

k<=2*log2(10^5)<34

转载请注明出处:寻找&星空の孩子

  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4. #define LL long long
  5. using namespace std;
  6. LL num[];
  7. LL sum[];
  8. int main()
  9. {
  10. int T;
  11. scanf("%d",&T);
  12. while(T--)
  13. {
  14. LL n;
  15. scanf("%lld",&n);
  16. num[]=sum[]=;
  17. for(int i=; i<=n; i++)
  18. {
  19. scanf("%lld",&num[i]);
  20. sum[i]=sum[i-]+num[i];
  21. }
  22. LL ans=;
  23. for(LL k=; k<=; k++)
  24. {
  25. LL l=,r=;//注意r的初始值在l的左边;因为存在1个值的情况!
  26. LL KL=1LL<<(k-);
  27. if(k==) KL--;
  28. LL KR=1LL<<(k);
  29. for(LL i=; i<=n; i++)
  30. {
  31. l=max(i,l);//区间左边界
  32. while(l<=n&&sum[l]-sum[i-]<KL) l++;//确定左边界
  33. r=max(l-,r);//区间右边界,注意r在l前的时候从l-1开始
  34. while(r+<=n&&sum[r+]-sum[i-]>=KL&&sum[r+]-sum[i-]<KR) r++;//确定区间右边界
  35. if(r<l) continue;
  36. ans+=k*((i+l)+(i+r))*(r-l+)/;
  37. }
  38. }
  39. printf("%lld\n",ans);
  40. }
  41. return ;
  42. }
  1.  

1008题         链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360

Hiking

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 544    Accepted Submission(s):
290
Special Judge

Problem Description
There are n soda
conveniently labeled by 1,2,…,n.
beta, their best friends, wants to invite some soda to go hiking.
The i-th
soda will go hiking if the total number of soda that go hiking except him is no
less than li and
no larger than ri.
beta will follow the rules below to invite soda one by one:
1. he selects a
soda not invited before;
2. he tells soda the number of soda who agree to go
hiking by now;
3. soda will agree or disagree according to the number he
hears.

Note: beta will always tell the truth and soda will agree if and
only if the number he hears is no less than li and
no larger than ri,
otherwise he will disagree. Once soda agrees to go hiking he will not regret
even if the final total number fails to meet some soda's will.

Help beta
design an invitation order that the number of soda who agree to go hiking is
maximum.

 
Input
There are multiple test cases. The first line of input
contains an integer T,
indicating the number of test cases. For each test case:

The first
contains an integer n (1≤n≤105),
the number of soda. The second line constains n integers l1,l2,…,ln.
The third line constains n integers r1,r2,…,rn. (0≤li≤ri≤n)
It
is guaranteed that the total number of soda in the input doesn't exceed 1000000.
The number of test cases in the input doesn't exceed 600.

 
Output
For each test case, output the maximum number of soda.
Then in the second line output a permutation of 1,2,…,n denoting
the invitation order. If there are multiple solutions, print any of
them.
 
Sample Input
4
8
4 1 3 2 2 1 0 3
5 3 6 4 2 1 7 6
8
3 3 2 0 5 0 3 6
4 5 2 7 7 6 7 6
8
2 2 3 3 3 0 0 2
7 4 3 6 3 2 2 5
8
5 6 5 3 3 1 2 4
6 7 7 6 5 4 3 5
 
Sample Output
7
1 7 6 5 2 4 3 8
8
4 6 3 1 2 5 8 7
7
3 6 7 1 5 2 8 4
0
1 2 3 4 5 6 7 8
 
Source
 

题意:问邀请的顺序,使得最终去的人最多,每个人有一个区间[l,r]的人数要求

分析:用优先队列维护,按照r从小到大;不是很难注意细节。

  1. #include<stdio.h>
  2. #include<queue>
  3. #include<algorithm>
  4. #include<string.h>
  5. using namespace std;
  6. const int N = ;
  7. struct nnn
  8. {
  9. int l,r,id;
  10. }node[N];
  11. struct NNNN
  12. {
  13. int r,id;
  14. friend bool operator<(NNNN aa,NNNN bb)
  15. {
  16. return aa.r>bb.r;
  17. }
  18. };
  19.  
  20. priority_queue<NNNN>q;
  21. bool cmp1(nnn aa, nnn bb)
  22. {
  23. return aa.l<bb.l;
  24. }
  25. int id[N];
  26. bool vist[N];
  27. int main()
  28. {
  29. int T,n,ans;
  30. NNNN now;
  31. scanf("%d",&T);
  32. while(T--)
  33. {
  34. scanf("%d",&n);
  35. ans=;
  36.  
  37. /*for(int i=1; i<=n; i++)
  38. printf("%d ",i);
  39. printf("=id\n\n");*/
  40. for(int i=; i<n; i++)
  41. {
  42. scanf("%d",&node[i].l);
  43. node[i].id=i+;
  44. }
  45. for(int i=; i<n; i++)
  46. scanf("%d",&node[i].r);
  47. sort(node,node+n,cmp1);
  48. memset(vist,,sizeof(vist));
  49. int i=;
  50. while(i<n)
  51. {
  52. bool ff=;
  53. while(i<n&&ans>=node[i].l&&ans<=node[i].r)
  54. {
  55. now.r=node[i].r;
  56. now.id=node[i].id;
  57. q.push(now);
  58. //printf("in = %d\n",now.id);
  59. i++;
  60. ff=;
  61. }
  62. if(ff)i--;
  63. while(!q.empty())
  64. {
  65. now=q.top(); q.pop();
  66. if(now.r<ans)continue;
  67. //printf("out = %d\n",now.id);
  68. ans++;
  69. id[ans]=now.id;
  70. vist[now.id]=;
  71. if(node[i+].l<=ans)
  72. break;
  73. }
  74. i++;
  75. }
  76. while(!q.empty())
  77. {
  78. now=q.top(); q.pop();
  79. if(now.r<ans)continue;
  80. //printf("out = %d\n",now.id);
  81. ans++;
  82. id[ans]=now.id;
  83. vist[now.id]=;
  84. }
  85.  
  86. bool fff=;
  87. printf("%d\n",ans);
  88. for( i=; i<=ans; i++)
  89. if(i>)
  90. printf(" %d",id[i]);
  91. else if(i==)
  92. printf("%d",id[i]);
  93. if(ans)fff=;
  94. for( i=; i<=n; i++)
  95. if(vist[i]==&&fff)
  96. printf(" %d",i);
  97. else if(vist[i]==)
  98. printf("%d",i),fff=;
  99. printf("\n");
  100. }
  101. }
  1.  

1011题      链接:http://acm.hdu.edu.cn/showproblem.php?pid=5363

Key Set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 420    Accepted Submission(s):
275

Problem Description
soda has a set S with n integers {1,2,…,n}.
A set is called key set if the sum of integers in the set is an even number. He
wants to know how many nonempty subsets of S are
key set.
 
Input
There are multiple test cases. The first line of input
contains an integer T (1≤T≤105),
indicating the number of test cases. For each test case:

The first line
contains an integer n (1≤n≤109),
the number of integers in the set.

 
Output
For each test case, output the number of key sets
modulo 1000000007.
 
Sample Input
4
1
2
3
4
 
Sample Output
0
1
3
7
 
Source
 

  1.  
  1. #include<stdio.h>
  2. #define LL long long
  3. #define mod 1000000007
  4. LL ppow(LL a,LL b)
  5. {
  6. LL c=;
  7. while(b)
  8. {
  9. if(b&) c=c*a%mod;
  10. b>>=;
  11. a=a*a%mod;
  12. }
  13. return c;
  14. }
  15. int main()
  16. {
  17. int T;
  18. LL n;
  19. scanf("%d",&T);
  20. while(T--)
  21. {
  22. scanf("%lld",&n);
  23. printf("%lld\n",ppow(,n-)-);
  24. }
  25. return ;
  26. }

2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)的更多相关文章

  1. 2016 Multi-University Training Contest 10 solutions BY BUPT

    1001. 一个数组上的两个区间求中位数,可以通过分类讨论直接找到中位数,复杂度O(1).不过本题数据较小,优美的log(n)也可过. 1002. 直接求得阴影面积表达式即可. 1003. 二分完成时 ...

  2. 2016 Multi-University Training Contest 9 solutions BY 金策工业综合大学

    A Poor King Tag: Reversed BFS Preprocessing is needed to calculate answers for all positions (states ...

  3. 2016 Multi-University Training Contest 8 solutions BY 学军中学

    1001: 假设有4个红球,初始时从左到右标为1,2,3,4.那么肯定存在一种方案,使得最后结束时红球的顺序没有改变,也是1,2,3,4. 那么就可以把同色球都写成若干个不同色球了.所以现在共有n个颜 ...

  4. 2016 Multi-University Training Contest 7 solutions BY SYSU

    Ants 首先求出每个点的最近点. 可以直接对所有点构造kd树,然后在kd树上查询除本身以外的最近点,因为对所有点都求一次,所以不用担心退化. 也可以用分治做,同样是O(NlogN)的复杂度. 方法是 ...

  5. 2016 Multi-University Training Contest 6 solutions BY UESTC

    A Boring Question \[\sum_{0\leq k_{1},k_{2},\cdots k_{m}\leq n}\prod_{1\leq j< m}\binom{k_{j+1}}{ ...

  6. 2016 Multi-University Training Contest 5 solutions BY ZSTU

    ATM Mechine E(i,j):存款的范围是[0,i],还可以被警告j次的期望值. E(i,j) = \(max_{k=1}^{i}{\frac{i-k+1}{i+1} * E(i-k,j)+\ ...

  7. 2016 Multi-University Training Contest 4 solutions BY FZU

    1001 Another Meaning 对于这个问题,显然可以进行DP: 令dp[i]表示到i结尾的字符串可以表示的不同含义数,那么考虑两种转移: 末尾不替换含义:dp[i - 1] 末尾替换含义: ...

  8. 2016 Multi-University Training Contest 3 solutions BY 绍兴一中

    1001 Sqrt Bo 由于有\(5\)次的这个限制,所以尝试寻找分界点. 很容易发现是\(2^{32}\),所以我们先比较输入的数字是否比这个大,然后再暴力开根. 复杂度是\(O(\log\log ...

  9. 2016 Multi-University Training Contest 2 solutions BY zimpha

    Acperience 展开式子, \(\left\| W-\alpha B \right\|^2=\displaystyle\alpha^2\sum_{i=1}^{n}b_i^2-2\alpha\su ...

随机推荐

  1. 包建强的培训课程(15):Android App热修复技术

    @import url(/css/cuteeditor.css); Normal 0 10 pt 0 2 false false false EN-US ZH-CN X-NONE $([{£¥·‘“〈 ...

  2. 包建强的培训课程(17):Java代码敏捷之道

    第1讲 千言万语聊注释 按图索骥 奇葩注释“赏析” Git提交的学问 第2讲 RxJava:函数式编程 从一只猫的故事说起 背压 第3讲 代码瘦身 抽象相同逻辑的代码 查找相似代码 AOP一瞥 第4讲 ...

  3. PLSQL使用scott登录

    Oracle有3种用户: system.sys.scott,其中system和sys的区别在与能否创建数据库,sys用户登录才可以创建数据库,而scott是给初学者学习的用户,学习者可以用Scott登 ...

  4. 五、activiti工作流-学生请假流程

    有了上一节的基础,这节主要讲如何创建一个学生请假流程.部署.运行流程实例.查看任务.执行任务.判断流程实例状态.历史任务(实例)查询.历史活动节点查询 记住,一个正在执行的流程,他的流程定义id无论到 ...

  5. 原生Ajax GET+POST请求无刷新实现文本框用户名是否被注册

    实现Ajax需要使用一个核心对象XMLHttpRequest XMLHttpRequest对象可以在不向服务器提交整个页面的情况下,实现局部更新网页.当页面全部加载完毕后,客户端通过该对象向服务器请求 ...

  6. 长沙IT二十年

    长沙IT二十年 古语有云“近代中国,湖南独撑半边天”,近代中国以来,多少仁人志士从湖湘这片热土出发,在中华大地上,挥毫泼墨,为中华民族的繁荣昌盛做出了不可磨灭的贡献.而今天,随着互联网时代的到来,长沙 ...

  7. java提高(8)---ArrayList源码

    ArrayList源码 一.定义 public class ArrayList<E> extends AbstractList<E> implements List<E& ...

  8. 项目中使用sass,如何实现自动编译

    本次React项目中用到了Sass,在一个主文件main.scss中引入了其余的scss文件,然后把main.scss文件编译为main.css文件,最后在项目的主文件入口index.html中引入m ...

  9. 三方面搞定http协议之“请求方法”

    我所熟知的请求方法一共有六种: GET 请求指定的页面信息,并返回实体主体. POST 向指定资源提交数据进行处理请求(例如提交表单或者上传文件) PUT 从客户端向服务器传送的数据取代指定的文档的内 ...

  10. Python快速学习07:文本文件的操作

    作者:Jeff Lee 出处:http://www.cnblogs.com/Alandre/ 欢迎转载,也请保留这段声明.谢谢! 系列文章:[传送门] Python具有基本的文本文件读写功能.Pyth ...