官方解题报告: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个人,要求每个人得到蛋糕大小总和相等


 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = + ;
int ret[][MAXN];
int vis[], a[];
int tot, tar; bool dfs(int dep, int now, int u, int c)
{
if (now == )
{
int k = ;
while (vis[k] != -) ++ k;
vis[k] = c;
if (dfs(dep + , a[k], k + , c)) return true;
vis[k] = -;
return false;
}
if (now == tar)
{
if (dep == tot) return true;
else return dfs(dep, , , c + );
}
for (int i = u; i < tot; ++ i)
{
if (vis[i] == - && now + a[i] <= tar)
{
vis[i] = c;
if (dfs(dep + , now + a[i], i + , c)) return true;
vis[i] = -;
}
}
return false;
} int main()
{
int T;
scanf("%d", &T);
for (int cas = ; cas <= T; ++ cas)
{
int n, k;
scanf("%d%d", &n, &k);
//fprintf(stderr, "%d %d\n", n, k);
LL sum = (LL)n * (n + ) / ;
if (sum % k == && n >= k * - )
{
while (n >= )
{
for (int i = ; i < k; ++ i) ret[i][++ ret[i][]] = n - i;
for (int i = ; i < k; ++ i) ret[i][++ ret[i][]] = n - k * + i + ;
n -= k * ;
}
tot = n;
tar = n * (n + ) / / k;
for (int i = ; i < tot; ++ i) a[i] = tot - i;
for (int i = ; i < tot; ++ i) vis[i] = -;
dfs(, , , );
for (int i = ; i < tot; ++ i)
{
ret[vis[i]][++ ret[vis[i]][]] = a[i];
}
for (int i = ; i < k; ++ i)
{
printf("%d ", ret[i][]);
for (int j = ; j <= ret[i][]; ++ j) printf(" %d", ret[i][j]);
puts("");
}
}
else puts("NO");
}
return ;
}

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

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

 #include<stdio.h>
#include<math.h>
#include<algorithm>
#define LL long long
using namespace std;
LL num[];
LL sum[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL n;
scanf("%lld",&n);
num[]=sum[]=;
for(int i=; i<=n; i++)
{
scanf("%lld",&num[i]);
sum[i]=sum[i-]+num[i];
}
LL ans=;
for(LL k=; k<=; k++)
{
LL l=,r=;//注意r的初始值在l的左边;因为存在1个值的情况!
LL KL=1LL<<(k-);
if(k==) KL--;
LL KR=1LL<<(k);
for(LL i=; i<=n; i++)
{
l=max(i,l);//区间左边界
while(l<=n&&sum[l]-sum[i-]<KL) l++;//确定左边界
r=max(l-,r);//区间右边界,注意r在l前的时候从l-1开始
while(r+<=n&&sum[r+]-sum[i-]>=KL&&sum[r+]-sum[i-]<KR) r++;//确定区间右边界
if(r<l) continue;
ans+=k*((i+l)+(i+r))*(r-l+)/;
}
}
printf("%lld\n",ans);
}
return ;
}

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从小到大;不是很难注意细节。

 #include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
const int N = ;
struct nnn
{
int l,r,id;
}node[N];
struct NNNN
{
int r,id;
friend bool operator<(NNNN aa,NNNN bb)
{
return aa.r>bb.r;
}
}; priority_queue<NNNN>q;
bool cmp1(nnn aa, nnn bb)
{
return aa.l<bb.l;
}
int id[N];
bool vist[N];
int main()
{
int T,n,ans;
NNNN now;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ans=; /*for(int i=1; i<=n; i++)
printf("%d ",i);
printf("=id\n\n");*/
for(int i=; i<n; i++)
{
scanf("%d",&node[i].l);
node[i].id=i+;
}
for(int i=; i<n; i++)
scanf("%d",&node[i].r);
sort(node,node+n,cmp1);
memset(vist,,sizeof(vist));
int i=;
while(i<n)
{
bool ff=;
while(i<n&&ans>=node[i].l&&ans<=node[i].r)
{
now.r=node[i].r;
now.id=node[i].id;
q.push(now);
//printf("in = %d\n",now.id);
i++;
ff=;
}
if(ff)i--;
while(!q.empty())
{
now=q.top(); q.pop();
if(now.r<ans)continue;
//printf("out = %d\n",now.id);
ans++;
id[ans]=now.id;
vist[now.id]=;
if(node[i+].l<=ans)
break;
}
i++;
}
while(!q.empty())
{
now=q.top(); q.pop();
if(now.r<ans)continue;
//printf("out = %d\n",now.id);
ans++;
id[ans]=now.id;
vist[now.id]=;
} bool fff=;
printf("%d\n",ans);
for( i=; i<=ans; i++)
if(i>)
printf(" %d",id[i]);
else if(i==)
printf("%d",id[i]);
if(ans)fff=;
for( i=; i<=n; i++)
if(vist[i]==&&fff)
printf(" %d",i);
else if(vist[i]==)
printf("%d",i),fff=;
printf("\n");
}
}

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
 


 #include<stdio.h>
#define LL long long
#define mod 1000000007
LL ppow(LL a,LL b)
{
LL c=;
while(b)
{
if(b&) c=c*a%mod;
b>>=;
a=a*a%mod;
}
return c;
}
int main()
{
int T;
LL n;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
printf("%lld\n",ppow(,n-)-);
}
return ;
}

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. orcale mysql基本的分页查询法

    orcale分页查询sql语句: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A WHERE ROWNU ...

  2. 12Js_原型对象

    对象描述: 1. 每个对象中都有一个_proto_属性. JS世界中没有类(模具)的概念,对象是从另一个对象(原型)衍生出来的,所以每个对象中会有一个_proto_属性指向它的原型对象.(参考左上角的 ...

  3. Redis学习笔记之延时队列

    目录 一.业务场景 二.Redis延时队列 一.业务场景 所谓延时队列就是延时的消息队列,下面说一下一些业务场景比较好理解 1.1 实践场景 订单支付失败,每隔一段时间提醒用户 用户并发量的情况,可以 ...

  4. Effective Java 第三版——60. 需要精确的结果时避免使用float和double类型

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  5. logstash笔记(二)——grok之match

    官方文档: https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html 基本语法: %{SYNTAX:SEMA ...

  6. Python+selenium 2【测试报告】

    HTML报告 http://tungwaiyip.info/software/HTMLTestRunner.html   下载地址 这个扩展非常简单,只有一个HTMLTestRunner.py文件,选 ...

  7. Spring Boot – 自定义PropertyEditor

    前言 PropertyEditor最初是属于Java Bean规范定义的,有意思的是,Spring也大规模的使用了PropertyEditors,以便实现以各种形式展现对象的属性: 举个例子,常见的用 ...

  8. ReentrantLock 详解

    ReentrantLock的功能是实现代码段的并发访问控制,也就是通常意义上所说的锁,java中实现锁有两种方式,一种是本文所提的ReentrantLock,另一种是synchronized.Reen ...

  9. 小程序开发--移动端分辨率与rpx

    首先说一个很有意思的问题:一块720p的屏幕和1080p的屏幕那个大? 这个问题很有代表性,如果手机竖着放,720p=720px*1280px,而1080p=1080px*1920px;那么在宽度上, ...

  10. 编写高质量代码改善java程序的151个建议——[110-117]异常及Web项目中异常处理

    原创地址:http://www.cnblogs.com/Alandre/(泥沙砖瓦浆木匠),需要转载的,保留下! 文章宗旨:Talk is cheap show me the code. 大成若缺,其 ...