The 2014 ACM-ICPC Asia Regional Anshan
继续复盘下一场Regional!
【A】-_-///
【B】模拟(之前每次遇到模拟、暴搜都直接跳了,题目太长也是一个原因...下次是在不行可以尝试一下)
【C】数论 互质、容斥?
【F】-_-///
【G】最小割的灵活运用
【H】搜索+打表
【J】-_-///
【K】计算几何、置换群(Polya计数)
【L】AC自动机+树链剖分
【D】 HDU 5073
Galaxy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Special Judge
To be fashionable, DRD also bought himself a galaxy. He named it Rho Galaxy. There are n stars in Rho Galaxy, and they have the same weight, namely one unit weight, and a negligible volume. They initially lie in a line rotating around their center of mass.Everything runs well except one thing. DRD thinks that the galaxy rotates too slow. As we know, to increase the angular speed with the same angular momentum, we have to decrease the moment of inertia.
The moment of inertia I of a set of n stars can be calculated with the formula
where wi is the weight of star i, di is the distance form star i to the mass of center.As DRD’s friend, ATM, who bought M78 Galaxy, wants to help him. ATM creates some black holes and white holes so that he can transport stars in a negligible time. After transportation, the n stars will also rotate around their new center of mass. Due to financial pressure, ATM can only transport at most k stars. Since volumes of the stars are negligible, two or more stars can be transported to the same position.
Now, you are supposed to calculate the minimum moment of inertia after transportation.
For each test case, the first line contains two integers, n(1 ≤ n ≤ 50000) and k(0 ≤ k ≤ n), as mentioned above. The next line contains n integers representing the positions of the stars. The absolute values of positions will be no more than 50000.
- - -
【Sample Output】
0.5
【题意】
平面中有n个点,最多可以移动k个点,使原题条件中的I达到最小值。物理题,计算转动惯量。
【分析】
开始的时候真是死活看不懂题......
原题中的wi始终为1,即可忽略,然后di指的是x距离所有点重心的距离,这里的重心即是所有点坐标的平均值了。所以原式可以写成这样:

分析一下这个东西跟方差很像,所以可以写成:

然后:

最后:

基本的I的计算方法就推导出来了,接下来是k的问题。
为了让I尽可能的小,也就是让方差尽可能的小,那么最佳的方案就是把距离重心最远的k个点都移到重心去。则首先根据坐标排序,从两端开始枚举取数,前面取i个那最后就取k-i个,找到一种最佳的取数方案把最外围的点都移掉即可。
/* ***********************************************
MYID : Chen Fan
LANG : G++
PROG : HDU 5073
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; long long a[],sum[],sum2[]; int main()
{
int t;
scanf("%d",&t);
for (int tt=;tt<=t;tt++)
{
int n,k;
scanf("%d%d",&n,&k); for (int i=;i<=n;i++) scanf("%lld",&a[i]); if (n==k)
{
printf("0\n");
continue;
} sort(&a[],&a[n+]);
memset(sum,,sizeof(sum));
memset(sum2,,sizeof(sum2));
for (int i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i];
sum2[i]=sum2[i-]+a[i]*a[i];
} double mi=sum2[n-k]-(double)sum[n-k]*sum[n-k]/(n-k);
for (int i=;i<=k;i++)
{
double temp=sum2[n-k+i]-sum2[i]-(double)(sum[n-k+i]-sum[i])*(sum[n-k+i]-sum[i])/(n-k);
if (mi>temp) mi=temp;
} printf("%.10f\n",mi);
} return ;
}
杭电上%lld和%I64d老是出问题...%lld提交通不过的话改成%I64d应该就可以了
【E】 HDU 5074
Hatsune Miku
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Today you want to compose a song, which is just a sequence of notes. There are only m different notes provided in the package. And you want to make a song with n notes.
Also, you know that there is a system to evaluate the beautifulness of a song. For each two consecutive notes a and b, if b comes after a, then the beautifulness for these two notes is evaluated as score(a, b).So the total beautifulness for a song consisting of notes a1, a2, . . . , an, is simply the sum of score(ai, ai+1) for 1 ≤ i ≤ n - 1.
Now, you find that at some positions, the notes have to be some specific ones, but at other positions you can decide what notes to use. You want to maximize your song’s beautifulness. What is the maximum beautifulness you can achieve?
For each test case, the first line contains two integers n(1 ≤ n ≤ 100) and m(1 ≤ m ≤ 50) as mentioned above. Then m lines follow, each of them consisting of m space-separated integers, the j-th integer in the i-th line for score(i, j)( 0 ≤ score(i, j) ≤ 100). The next line contains n integers, a1, a2, . . . , an (-1 ≤ ai ≤ m, ai ≠ 0), where positive integers stand for the notes you cannot change, while negative integers are what you can replace with arbitrary notes. The notes are named from 1 to m.
- - - - - - -
【Sample Output】
【分析】
简单的签到DP,f(i,j)表示摆到第i个符号,且最后一个取j的最大分数,则f(i,j)=max(f(i-1,k)+score(k,j))
/* ***********************************************
MYID : Chen Fan
LANG : G++
PROG : HDU 5074
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int a[];
int f[][];
int score[][]; int main()
{
int t;
scanf("%d",&t);
for (int tt=;tt<=t;tt++)
{
int n,m;
scanf("%d%d",&n,&m); memset(score,,sizeof(score));
for (int i=;i<=m;i++)
for (int j=;j<=m;j++) scanf("%d",&score[i][j]); for (int i=;i<=n;i++) scanf("%d",&a[i]); memset(f,,sizeof(f));
for (int i=;i<=n;i++)
{
if (a[i]>)
if (a[i-]>) f[i][a[i]]=f[i-][a[i-]]+score[a[i-]][a[i]];
else for (int j=;j<=m;j++)
f[i][a[i]]=max(f[i][a[i]],f[i-][j]+score[j][a[i]]);
else
if (a[i-]>)
for (int j=;j<=m;j++) f[i][j]=f[i-][a[i-]]+score[a[i-]][j];
else for (int j=;j<=m;j++)
for (int k=;k<=m;k++) f[i][j]=max(f[i][j],f[i-][k]+score[k][j]);
} if (a[n]>) printf("%d\n",f[n][a[n]]);
else
{
int ma=;
for (int i=;i<=m;i++)
if (ma<f[n][i]) ma=f[n][i];
printf("%d\n",ma);
}
} return ;
}
【I】 HDU 5078
Osu!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Special Judge
Now, you want to write an algorithm to estimate how diffecult a game is.To simplify the things, in a game consisting of N points, point i will occur at time ti at place (xi, yi), and you should click it exactly at ti at (xi, yi). That means you should move your cursor from point i to point i+1. This movement is called a jump, and the difficulty of a jump is just the distance between point i and point i+1 divided by the time between ti and ti+1. And the difficulty of a game is simply the difficulty of the most difficult jump in the game.
Now, given a description of a game, please calculate its difficulty.
For each test case, the first line contains an integer N (2 ≤ N ≤ 1000) denoting the number of the points in the game. Then N lines follow, the i-th line consisting of 3 space-separated integers, ti(0 ≤ ti < ti+1 ≤ 106), xi, and yi (0 ≤ xi, yi ≤ 106) as mentioned above.
Your answer will be considered correct if and only if its absolute or relative error is less than 1e-9.
【Sample Output】
9.2195444573
54.5893762558
【分析】
签到题,唯一要注意的是数据范围,两个1e6数量级的数相乘有超int的可能。
The 2014 ACM-ICPC Asia Regional Anshan的更多相关文章
- HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP
Clone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) Total Submiss ...
- 2014 ACM/ICPC Asia Regional Anshan Online
默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorit ...
- HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)
Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node ...
- HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)
Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself ...
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...
- 2014 ACM/ICPC Asia Regional Shanghai Online
Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...
- 2014 ACM/ICPC Asia Regional Guangzhou Online
Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚 ...
- 2014 ACM/ICPC Asia Regional 北京 Online
G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushroo ...
- 2014 ACM/ICPC Asia Regional Xi'an Online
03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为 ...
随机推荐
- vs当前不会命中断点,还没有为该文档加载任何符号
今天发布网站之后,附加进程却怎么页不能命中断点,后来发现原来,我将发布的web.config文件覆盖掉了新生成的配置文件,其中一项:<compilation debug="false& ...
- Application的多种值判断测试程序
Application.Contents.Remove("FriendLink") Response.Write("Application.Contents.Remove ...
- OpenGL-------状态机
状态机就是一种存在于理论中的机器,它具有以下的特点: 1. 它有记忆的能力,能够记住自己当前的状态. 2. 它可以接收输入,根据输入的内容和自己的状态,修改自己的状态,并且可以得到输出. 3. 当它进 ...
- JS定时器的使用--无缝滚动
<title>无标题文档</title> <style> * {margin:0; padding:0;} #div1{width:1172px; height:2 ...
- nginx slab内存管理
本来这一篇作为nginx系列的开头是不合适的,不过由于nginx进程框架自己的梳理还没完成,这部分又刚好整理完了,就从这开始吧.这儿谈的是nginx的slab的内存管理方式,这种方式的内存管理在ngi ...
- java导出和读取excel数据
使用的是poi的jar包 下载地址http://poi.apache.org/download.html 主要是把jar包导入,直接新建一个列子测试一下就明白了.使用起来还是比较方便的,代码里面的原理 ...
- cordova插件开发-1
这是初级编,实现了js调用Android代码 首先需要编写java代码: public class AppUpdate extends CordovaPlugin { @Override public ...
- JS中三目运算符和if else的区别分析与示例
本文是通过示例详细分析了JS中三目运算符和if else的区别,是篇非常不错的文章,这里推荐给大家. 今天写了一个图片轮播的小demo,用到了判断 先试了一下if else,代码如下: 复制代码代 ...
- nginx及php版本号隐藏
配置完一台服务器后,并不是就可以高枕无忧了,前不久刚刚爆发的PHP 5.3.9版本的漏洞也搞得人心惶惶,所以说经常关注安全公告并及时升级服务器也是必要的.一般来说,黑客攻击服务器的首要步骤就是收集信息 ...
- struts2整合spring应用实例
我们知道struts1与spring整合是靠org.springframework.web.struts.DelegatingActionProxy来实现的,以下通过具体一个用户登录实现来说明stru ...