The 2014 ACMICPC Asia Regional Xian Online
【B】后缀数组
【C】染色,DP(感觉可出)
【D】BFS搜索,有点麻烦
【G】概率DP+状态压缩
【I】矩阵快速幂(队友已出)
【J】树的分治
【A】
Post Robot
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.
After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will make a comment “MAI MAI MAI!”, and go on reading the post.
In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
The size of the article does not exceed 8KB.
Apple bananaiPad lemon ApplepiSony Tim cook is doubi from Apple
iPhoneipad
iPhone30 is so biiiiiiig Microsoft
makes good App.
【Sample Output】
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
SONY DAFA IS GOOD!
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
【分析】
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
● In the beginning of the game, there are a lot of piles of beads.
● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing)
● If after a player's turn, there is no beads left, the player is the winner.
Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
For each test case, the first line contains a postive integer n(n < 105) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer ai(ai < 231) means there are ai beads in the i-th pile.
【Sample Output】
Win
Lose
Lose
【题意】
Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
At the beginning, the two dices may face different(which means there exist some i, ai ≠ bi). Ddy wants to make the two dices look the same from all directions(which means for all i, ai = bi) only by the following four rotation operations.(Please read the picture for more information) Now Ddy wants to calculate the minimal steps that he has to take to achieve his goal.
For each case, the first line consists of six integers a1,a2,a3,a4,a5,a6, representing the numbers on dice A.
The second line consists of six integers b1,b2,b3,b4,b5,b6, representing the numbers on dice B.
【Sample Output】
-
【题意】
/* ***********************************************
MYID : Chen Fan
LANG : G++
PROG : F1006
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef struct nod{
int a,b,c,d,e,f;
} node; node move1(node a)
{
node ret;
ret.a=a.d;ret.b=a.c;ret.c=a.a;
ret.d=a.b;ret.e=a.e;ret.f=a.f;
return ret;
} node move2(node a)
{
node ret;
ret.a=a.c;ret.b=a.d;ret.c=a.b;
ret.d=a.a;ret.e=a.e;ret.f=a.f;
return ret;
} node move3(node a)
{
node ret;
ret.a=a.f;ret.b=a.e;ret.c=a.c;
ret.d=a.d;ret.e=a.a;ret.f=a.b;
return ret;
} node move4(node a)
{
node ret;
ret.a=a.e;ret.b=a.f;ret.c=a.c;
ret.d=a.d;ret.e=a.b;ret.f=a.a;
return ret;
} node q[];
int num[];
int head=,tail=; bool check(node a)
{
for (int i=;i<=tail;i++)
if (a.a==q[i].a&&a.b==q[i].b&&a.c==q[i].c&&a.d==q[i].d&&a.e==q[i].e&&a.f==q[i].f)
return true;
return false;
} int main()
{
node a,b;
while (scanf("%d",&a.a)!=EOF)
{
scanf("%d%d%d%d%d",&a.b,&a.c,&a.d,&a.e,&a.f);
scanf("%d%d%d%d%d%d",&b.a,&b.b,&b.c,&b.d,&b.e,&b.f); if (a.a==b.a&&a.b==b.b&&a.c==b.c&&a.d==b.d&&a.e==b.e&&a.f==b.f)
{
printf("0\n");
} else
{
q[]=a;
num[]=;
bool done=false;
head=;tail=;
while (head<=tail)
{
node temp=move1(q[head]);
if (temp.a==b.a&&temp.b==b.b&&temp.c==b.c&&temp.d==b.d&&temp.e==b.e&&temp.f==b.f)
{
printf("%d\n",num[head]+);
done=true;
break;
}
if (!check(temp))
{
tail++;
q[tail]=temp;
num[tail]=num[head]+;
} temp=move2(q[head]);
if (temp.a==b.a&&temp.b==b.b&&temp.c==b.c&&temp.d==b.d&&temp.e==b.e&&temp.f==b.f)
{
printf("%d\n",num[head]+);
done=true;
break;
}
if (!check(temp))
{
tail++;
q[tail]=temp;
num[tail]=num[head]+;
} temp=move3(q[head]);
if (temp.a==b.a&&temp.b==b.b&&temp.c==b.c&&temp.d==b.d&&temp.e==b.e&&temp.f==b.f)
{
printf("%d\n",num[head]+);
done=true;
break;
}
if (!check(temp))
{
tail++;
q[tail]=temp;
num[tail]=num[head]+;
} temp=move4(q[head]);
if (temp.a==b.a&&temp.b==b.b&&temp.c==b.c&&temp.d==b.d&&temp.e==b.e&&temp.f==b.f)
{
printf("%d\n",num[head]+);
done=true;
break;
}
if (!check(temp))
{
tail++;
q[tail]=temp;
num[tail]=num[head]+;
} head++;
}
if (!done) printf("-1\n");
}
} return ;
}
代码写得也比较丑
【启发】
当时初看题目的时候瞟了几眼直接就跳过了,-_-///事后感觉没什么可以做了才回来看的,然后才发现其实很简单。还是应该认真看看题,比赛的时候至少每道题都要看过去,说不定能找到一些突破点。
【H】
Number Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Special Judge
● ai ∈ [0,n] ● ai ≠ aj( i ≠ j )
For sequence a and sequence b, the integrating degree t is defined as follows(“⊕” denotes exclusive or):t = (a0 ⊕ b0) + (a1 ⊕ b1) +···+ (an ⊕ bn) (sequence B should also satisfy the rules described above)
Now give you a number n and the sequence a. You should calculate the maximum integrating degree t and print the sequence b.
For each case, the first line contains an integer n(1 ≤ n ≤ 105), The second line contains a0,a1,a2,...,an.
【Sample Output】
【题意】
题目给出一组A序列,t的值是等于B序列中的每一个对应的数与A序列异或之后的和。现在的要求就是求出能够使得t最大的B序列。
【分析】
首先我真的不是特别明白这道题为什么会用到Special Judge?
......按照我的想法,能使得t最大的B序列应该是唯一的,把所有数都化为二进制的形式,则为了使得Ai异或Bi的值最大,Bi的二进制数位要尽可能多地与Ai错开。
所以这样出来的数其实是一组两个的数,A序列是从0到n,B序列也是从0到n,且每个序列不出现重复的数字。对于每一个Ai,用一个等长的全1的二进制数去与之异或,就能得到对应的Bi,反过来对数Bi操作可以得到数Ai。其实就是构造出来之后使对应的Ai+Bi能等于一个全是1的二进制数。
如此就能构造出B序列了,下面是几个序列的对应关系,T这行表示异或结果
n=
-------------------
A B T
-------------------
n=
-------------------
A B T
-------------------
n=
-------------------
A B T
-------------------
当然这里有个顺序的问题,构造的时候从最大(二进制最长的数)的开始向小的数进行,保证使最终总的异或值最大,并且后来构造出来Bi的数比Ai小,避免了异或构造出来的数大于n的情况(真的可能会有啊)。
/* ***********************************************
MYID : Chen Fan
LANG : G++
PROG : H1008
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int pp[]={,,,,,,,,,,,,,,,,,};
int a[],b[]; int get(int s)
{
int ret=;
while (s>)
{
ret++;
s/=;
}
return ret;
} int main()
{
//freopen("H1008.txt","r",stdin);
//freopen("H1008out.txt","w",stdout); int n;
while (scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
for (int i=n;i>=;i--)
if (!a[i])
{
for (int j=i;j>=pp[get(i)-]+;j--)
{
int yh=j^pp[get(i)];
a[j]=yh;
a[yh]=j;
}
} long long ans=;
int x;
for (int i=;i<=n;i++)
{
scanf("%d",&x);
//x=i;
ans+=(long long )x^a[x];
b[i]=a[x];
}
printf("%lld\n",ans);
printf("%d",b[]);
for (int i=;i<=n;i++) printf(" %d",b[i]);
printf("\n");
} return ;
}
【启发】
虽然当时还没想明白Special Judge是为什么(现在还是不明白...),不过以后碰到有思路的就直接上吧,说不定就对了呢。
【K】
Ellipsoid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Special Judge
For each testcase, one line contains 6 real number a,b,c(0 < a,b,c,< 1),d,e,f(0 ≤ d,e,f < 1), as described above. It is guaranteed that the input data forms a ellipsoid. All numbers are fit in double.
0.04 0.01
【Sample Output】
1.0000000
【题意】
题目给出一个椭圆面的空间方程,要求计算出原点与椭圆面之间的最短距离。
【分析】
/* ***********************************************
MYID : Chen Fan
LANG : G++
PROG : HDU5017-Easy Simulated Annealing
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; double a,b,c,d,e,f;
double r=0.99;
double eps=1e-;
int dx[]={-,-,-,,,,,};
int dy[]={-,,,-,,-,,}; double cal(double x,double y)
{
double A=c,B=e*x+d*y,C=a*x*x+b*y*y+f*x*y-;
double delta=B*B-*A*C;
if (delta<) return 1e60;
double z1=(-B+sqrt(delta))//A,z2=(-B-sqrt(delta))//A;
if (z1*z1<z2*z2) return z1;
else return z2;
} double dis(double x,double y,double z)
{
return sqrt(x*x+y*y+z*z);
} double doit()
{
double step=;
double x=,y=,z;
while (step>eps)
{
z=cal(x,y);
for (int i=;i<;i++)
{
double xx=x+dx[i]*step,yy=y+dy[i]*step;
double zz=cal(xx,yy);
if (zz>1e30) continue;
if (dis(xx,yy,zz)<dis(x,y,z))
{
x=xx;
y=yy;
z=zz;
}
}
step*=r;
}
return dis(x,y,z);
} int main()
{
while (scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
printf("%.8f\n",doit());
return ;
}
个人认为这种搜索策略与真正的模拟退火算法还是有一点区别的,首先这里面根本没有涉及到向非最优解方向移动的情况。
我的理解是,这里模仿了模拟退火算法对温度控制的特性。由于是求解原点与椭球面的距离,这个结果必然是一个凸函数,则不断修正前进的方向并逐步缩小搜索范围,最终到达最优解。
首先指定一个步长与步长衰减速度(类退火速度),每次搜索完成一层,步长衰减一次,直到衰减程度在精度控制范围内。
三分:
二分用来求解线性函数的最优值,三分则是用来求解凸函数的最优值。
对于本题来说,基本想法是以x,y,z中的其中两个变量进行两次三分,而后计算出第三个变量,并以最终的距离作为判断函数。由于这里都是实数,两层三分需要迭代的次数比较难以控制,参数稍微修正得不对,精度与时间上就会出现比较大的问题,这两个要求的参数是对立的,精度高了耗时就长,时间控制了,可能最终结果又错了。
最后提交的是在超时边缘......中间出现了许多重复运算,这种还是不推荐使用了。
The 2014 ACMICPC Asia Regional Xian Online的更多相关文章
- The 2014 ACMICPC Asia Regional Xian
2题继续遗憾收场,每次都是只差最后一步.这一场却是之前那么多场中感觉距离奖牌最近的时候.好好总结一下经验教训,复盘之后好好准备下一场北京的最后一战吧. 一开始的状态非常不错,10分钟跟榜完成1A,第二 ...
- The 2014 ACM-ICPC Asia Regional Anshan
继续复盘下一场Regional! [A]-_-/// [B]模拟(之前每次遇到模拟.暴搜都直接跳了,题目太长也是一个原因...下次是在不行可以尝试一下) [C]数论 互质.容斥? [D]数学推导(方差 ...
- The 2014 ACMICPC Asia Invitational Xian
上半年邀请赛的时候真是险而又险地2题拿了个铜,确实其实跟没拿一样......现场前复盘一下,长长记性 [A]签到题 [B]最短路+DFS [C]最短路 [D]构造+欧拉回路 [E]数论,最佳平方逼近 ...
- The 2014 ACMICPC Asia Regional Shanghai Online
XorZip小队第一次合作,虽然结果还是有些可惜,但是状态和感觉都还不错. [A]数论+二分(-_-///) [B]Lucas定理+数位DP(-_-///) [C]LCA.LCT+树链剖分 [D]题目 ...
- The 2014 ACMICPC Asia Regional Guangzhou Online
[A]-_-/// [B]线段树+位运算(感觉可出) [C]地图BFS,找最长线 [D]地图BFS,加上各种复杂情况的最短路-_- [E]-_-/// [F]三分+圆与线段的交点,计算几何 [G]-_ ...
- The 2014 ACMICPC Asia Regional Beijing Online
[A]极角排序+树状数组 [B]计算几何,凸包(队友已出) [C]-_-///不懂 [D]数论,概率密度 [E]图的连通性+Floyed传递闭包+bitset [F]贪心 [G]签到题 [H]区间维护 ...
- The 2014 ACM-ICPC Asia Regional Anshan Online
[A]无向图的双联通子图计数.DP+状态压缩 [B]计算几何(点的旋转) [C]DP+状态压缩 [D]离散数学+DP (感觉可出) [E]概率DP [F]LCT模板题(-_-///LCT是啥!!!!) ...
- ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
Description Edward is a rich man. He owns a large factory for health drink production. As a matter o ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest A.Average Score B.Building Fire Stations C.Card G ...
随机推荐
- 硬盘安装win8系统方法汇总
从硬盘安装 (推荐)硬盘安装方法一 使用Nt6 hdd installer进行安装,此方法适合XP,vista, Windows 7等系统. 下载Nt6 hdd installer(Win8硬盘安装工 ...
- python http请求
from httplib2 import Http def postDada(): http=Http() heads={"pragma":"no-cache" ...
- wifi的UI控制。打不开UI
部分主要是您要清楚WiFi作为什么功能,即WiFi是仅仅作为station功能,还是要开启p2p功能,当WiFi作为station功能时候开启的是wpa_supplicant服务,当WiFi作为p2p ...
- Unable to open connection to supplicant on "/data/misc/wifi/sockets/wlan0"
在调试android wifi UI 的时候,出现了 logcat: Unable to open connection to supplicant on "/data/misc/wifi ...
- 快速玩转Apple Pay开发
快速玩转Apple Pay开发 更新时间:2016年02月20日09时25分 来源:传智播客 Apple Pay 2016年2月18日上午,苹果公司宣布,与中国银联达成合作,正式在中国大陆上线Appl ...
- ng-option小解
ng-option 有数组,对象两种情况,但目前只接触过数组 数组: label for value in array 分为一般数组和对象数组 一般数组: <select ng-model=&q ...
- 标签—box-shadow
box-shadow:2px 3px 4px #CCC; 一个带外阴影的元素,阴影位置x轴偏移2px,y轴偏移3px,模糊范围4px,阴影颜色#CCC box-shadow:inset 0 -4px ...
- 初学.net 网页打开过程
一个网页打开的过程 1.进入控制器里的方法里 控制器的命名必须以Controll结尾前面的名字要和view层的命名一致 2.控制器完了以后 就进入view层对应的视图里 3.视图里调用model ...
- HDU 1698 <线段树,区间set>
题目连接 题意: 一条长为N的铜链子,每个结点的价值为1.有两种修改,l,r,z; z=2:表示把[l,r]区间内链子改为银质,价值为2. z=3:表示把[l,r]区间内链子改为金质,价值为3. 思路 ...
- javascript语句语义大全(3)
1. for(var i=0;i<10;i++){ } for循环,括号里面是循环条件,翻译过来是,初始设定1=0:没循环一次i会+1,直到i<10 2. var i=0: while(i ...