A hard Aoshu Problem http://acm.hdu.edu.cn/showproblem.php?pid=3699

用深搜写排列,除法要注意,还有不能有前导零。当然可以5个for,但是如果有很多个,dfs还是好的。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
char sa[M],sb[M],sc[M],ha[M],hb[M],op[]="+-*/";
int val[];
bool use[];
map<string,bool> mp;
string str;
bool prezero(char s[]){
if(strlen(s)>&&!val[s[]-'A']) return true; return false;
}
int getint(char s[]){
int res=;
for(int i=;s[i];i++){
res=(res<<)+(res<<)+val[s[i]-'A'];
}
return res;
}
int solve(const int &a,const char &ope,const int &b){
if(ope=='+') return a+b;
if(ope=='-') return a-b;
if(ope=='*') return a*b;
if(b&&!(a%b))return a/b;
return -;
}
void flag(const int &a,const char &ope,const int &b){
sprintf(ha,"%d",a);
sprintf(hb,"%d",b);
str=(string)ha+ope+(string)hb;
mp[str]=true;
}
void dfs(int t){
if(t==){
if(prezero(sa)||prezero(sb)||prezero(sc)) return ;
int a=getint(sa);
int b=getint(sb);
int c=getint(sc);
for(int i=;i<;i++){
if(solve(a,op[i],b)==c){
flag(a,op[i],b);
}
}
return ;
}
for(int i=;i<;i++){
if(!use[i]){
val[t]=i;
use[i]=true;
dfs(t+);
use[i]=false;
}
}
}
int main(){
int t;
while(~scanf("%d",&t)){
while(t--){
scanf("%s%s%s",sa,sb,sc);
mt(use,);
mp.clear();
dfs();
printf("%d\n",mp.size());
}
}
return ;
}

Fermat Point in Quadrangle http://acm.hdu.edu.cn/showproblem.php?pid=3694

全一个点跑不出来,特判一下。

 #include<cstdio>
#include<cmath>
const double eps=1e-;
struct point{
double x,y;
}p[];
class Fermatpoint {//多边形的费马点
#define Q(x) ((x) * (x))
#define EQU(x, y) (fabs(x - y) < eps)
public:
point solve(int np, point p[]) {//顶点数np,多边形顶点数组p,返回多边形的费马点
double nowx=,nowy=,nextx=,nexty=;
for(int i = ; i < np; i++) {
nowx += p[i].x;
nowy += p[i].y;
}
for(nowx /= np, nowy /= np; ; nowx = nextx, nowy = nexty) {
double topx = , topy = , bot = ;
for(int i = ; i < np; i++) {
double d = sqrt(Q(nowx -p[i].x) + Q(nowy - p[i].y));
topx += p[i].x / d;
topy += p[i].y / d;
bot += / d;
}
nextx = topx / bot;
nexty = topy / bot;
if(EQU(nextx, nowx) && EQU(nexty, nowy)) break;
}
point fp;
fp.x = nowx;
fp.y = nowy;
return fp;
}
} gx;
double Distance(point p1,point p2) {
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int main(){
while(~scanf("%lf%lf",&p[].x,&p[].y)){
for(int i=;i<;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
bool out=true;
for(int i=;i<;i++){
if(p[i].x!=-||p[i].y!=-){
out=false;
break;
}
}
if(out) break;
bool all=true;
for(int i=;i<;i++){
if(!EQU(p[i].x,p[].x)||!EQU(p[i].y,p[].y)){
all=false;
break;
}
}
if(all){
puts("0.0000");
continue;
}
point center=gx.solve(,p);
double ans=;
for(int i=;i<;i++){
ans+=Distance(center,p[i]);
}
printf("%.4f\n",ans);
}
return ;
}

Computer Virus on Planet Pandora http://acm.hdu.edu.cn/showproblem.php?pid=3695

粘贴代码,有空重写一下。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
const int MAXPATLEN=;/** 模式串长度 */
const int MAXPATNUM=;/** 模式串数目 */
const int MAXSTRLEN=;/** 文本串长度 */
class ACAuto { /**多串匹配(AC自动机)*/
static const int ALPHALEN = ;
static const int PATLEN = MAXPATLEN;
static const int PATNUM = MAXPATNUM;
static const int STRLEN = MAXSTRLEN;
struct Node {
int cnt;
Node *fail,*chds[ALPHALEN];
Node() : cnt(), fail(NULL) {
mt(chds,);
};
}*root;
int Hash(char a) {
return a-'A';
}
void build_ACAuto() {
Node **que = new Node*[PATNUM*PATLEN];
int f = , r = ;
root->fail = root;
for (int i = ; i < ALPHALEN; i++) {
Node *chd = root->chds[i];
if (chd == NULL) {
root->chds[i] = root;
} else {
chd->fail = root;
que[r++] = chd;
}
}
while (f != r) {
Node *now = que[f++];
for (int i = ; i < ALPHALEN; i++) {
Node *chd = now->chds[i];
if (chd != NULL) {
chd->fail = now->fail->chds[i];
que[r++] = chd;
} else {
now->chds[i] = now->fail->chds[i];
}
}
}
delete [] que;
}
void Insert(char str[PATLEN]) {
int str_len = strlen(str);
Node *now = root;
for (int i = ; i < str_len; i++) {
int cid = Hash(str[i]);
if (now->chds[cid] == NULL) now->chds[cid] = new Node();
now = now->chds[cid];
}
now->cnt++;
}
public:
ACAuto(char pat_list[PATNUM][PATLEN], int list_len) {
root = new Node();
for (int i = ; i < list_len; i++) {
Insert(pat_list[i]);
}
build_ACAuto();
}
/** * 计算文本串中匹配所有模式串的次数之和(直接传入文本串) * @param 模式串 * @return 匹配次数 */
int match_times(char str[STRLEN]) {
int str_len = strlen(str);
int times = ;
Node *now = root;
for (int i = ; i < str_len; i++) {
now = now->chds[Hash(str[i])];
times += now->cnt;
Node *tmp = now;
while (tmp != root) {
times += tmp->cnt;
tmp = tmp->fail;
}
}
return times;
}
/** * 计算文本串中匹配所有模式串的次数之和(在函数内逐字符读入文本串) * @return 匹配次数 */
int match_times() {
int times = ;
char c;
Node *now = root;
while (c = getchar(), !isalpha(c));
do {
now = now->chds[Hash(c)];
times += now->cnt;
Node *tmp = now;
while (tmp != root) {
times += tmp->cnt;
tmp = tmp->fail;
}
} while (c = getchar(), isalpha(c));
return times;
}
/** * 计算文本串中匹配到的模式串数目(直接传入文本串。将破坏结点的cnt信息!) * @return 匹配次数 */
int match_keynum(char str[STRLEN]) {
int str_len = strlen(str);
int times = ;
Node *now = root;
for (int i = ; i < str_len; i++) {
now = now->chds[Hash(str[i])];
Node *tmp = now;
while (tmp != root && tmp->cnt != -) {
times += tmp->cnt;
tmp->cnt = -;
tmp = tmp->fail;
}
}
return times;
}
/** * 计算文本串中匹配到的模式串数目(在函数内逐字符读入文本串。将破坏结点 * 的cnt信息!) * @return 匹配次数 */
int match_keynum() {
int times = ;
char c;
Node *now = root, *tmp;
while (c = getchar(), !isalpha(c));
do {
now = now->chds[Hash(c)];
tmp = now;
while (tmp != root && tmp->cnt != -) {
times += tmp->cnt;
tmp->cnt = -;
tmp = tmp->fail;
}
} while (c = getchar(), isalpha(c));
return times;
}
};
char g[MAXPATNUM][MAXPATLEN];
char op[MAXSTRLEN];
char str[MAXSTRLEN];
int main() {
int t,n;
while(~scanf("%d",&t)) {
while(t--){
scanf("%d",&n);
for(int i=; i<n; i++) {
scanf("%s",g[i]);
}
scanf("%s",op);
int ls=;
for(int i=;op[i];){
if(isalpha(op[i])){
str[ls++]=op[i++];
continue;
}
if(op[i]=='['){
int sum=;
int j;
for(j=i+;op[j];j++){
if(!isdigit(op[j])) break;
sum*=;
sum+=op[j]-'';
}
for(int k=;k<sum;k++){
str[ls++]=op[j];
}
i=j+;
}
}
int ans=;
str[ls]=;
ACAuto gx(g,n);
ans+=gx.match_keynum(str);
for(int i=,j=strlen(str)-;i<j;i++,j--){
swap(str[i],str[j]);
}
ans+=gx.match_keynum(str);
printf("%d\n",ans);
}
}
return ;
}

Selecting courses http://acm.hdu.edu.cn/showproblem.php?pid=3697

枚举时间加贪心选择终点靠前的,由于后台测试数据大于了题目描述,所以程序需具备鲁棒性。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
struct point{
int x,y;
friend bool operator <(const point &a,const point &b){
return a.y<b.y;
}
}p[M];
bool use[M];
int main(){
int n;
while(~scanf("%d",&n),n){
int big=;
for(int i=;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
p[i].x*=;
p[i].y*=;
big=max(big,p[i].y);
}
sort(p,p+n);
int ans=;
for(int s=;s<;s++){
mt(use,);
for(int now=s;now<big;now+=){
for(int i=;i<n;i++){
if(!use[i]&&p[i].x<now&&now<p[i].y){
use[i]=true;
break;
}
}
}
int sum=;
for(int i=;i<n;i++){
if(use[i]) sum++;
}
ans=max(ans,sum);
}
printf("%d\n",ans);
}
return ;
}

end

2010 Asia Fuzhou Regional Contest的更多相关文章

  1. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

  2. HDU 3698 Let the light guide us(DP+线段树)(2010 Asia Fuzhou Regional Contest)

    Description Plain of despair was once an ancient battlefield where those brave spirits had rested in ...

  3. HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  4. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  5. HDU 3696 Farm Game(拓扑+DP)(2010 Asia Fuzhou Regional Contest)

    Description “Farm Game” is one of the most popular games in online community. In the community each ...

  6. HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)

    Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...

  7. HDU 3686 Traffic Real Time Query System(双连通分量缩点+LCA)(2010 Asia Hangzhou Regional Contest)

    Problem Description City C is really a nightmare of all drivers for its traffic jams. To solve the t ...

  8. 2011 Asia Fuzhou Regional Contest

    Xiangqi http://acm.hdu.edu.cn/showproblem.php?pid=4121 模拟,用高内聚低耦合的思想来写模拟题还是很好的,提高了函数的可重用性,程序的可读性,正确性 ...

  9. HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang

    感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...

随机推荐

  1. GemFire 入门篇1:GemFire 是什么?

    一.GemFire是什么?   如果你了解Redis或memCached,那么恭喜,你很快就能理解GemFire是什么,没错,你可以把它理解为一个增强版的Redis,具体在哪些方面增强,我们日后慢慢聊 ...

  2. php常用函数集锦[备份用的]

    1.判断是否正确的日期格式 /** * 是否正确的日期 * * @access public */ private function _isdate($str,$format="Y-m-d ...

  3. 高性能MySQL——第一章MySQL的架构与历史

    1.可以使用SHOW TABLE STATUS查询表的相关信息. 2.默认存储引擎是InnoDB,如果没有什么很特殊的要求,InnoDB引擎是我们最好的选择. 3.mysql的infobright引擎 ...

  4. IT新人论成长

    说自己是新人,其实自己也不新了,2012年毕业,辗转3个城市,现在在上海一家公司,工资不到5K. 在来现在公司之前,我从事web后台开发,采用MVC模式,虽然做了不少的网站,但感觉自己的水平还是在底层 ...

  5. a 标签 跳转4种类型

    <a href=''  target=''>中的target有4种参数: '_self'   ,  '_parent'   ,  '_top'    和  '_blank' 在没有使用框架 ...

  6. Dapper多表查询(列名重复,类字段重复)映射方案

    1. 一个主名,一个别名,设计时候属性和字段命名不同. 这样主名和别名都可以用的,在主名与别人重复时候用别名(别名可以设计的明确一点长一点,比如类名和字段结合) 2. 或者找一个字段多的直接继承出一个 ...

  7. ios 工程图片清理shell

    #!/bin/shecho "随意删除@2x图片可能会引起错误 因为ios工程会更加前缀和分辨率自己找到@2x的图片 所以删除@2x图片时要慎重"read -n1 -p  &quo ...

  8. 小米miui5系统的webview在处理动画事件transitionEnd事件时,竟然要用transitionend才行

    一般的安卓系统用的是webkitTransitionEnd, 而小米的系统我用了webkitTransitionEnd事件无法执行,只能用transitionend才会被执行,怪

  9. Python学习教程(learning Python)--1.2.3 Python格式化输出百分比

    在有些情况下,需要百分比输出数据,我们可以继续使用Python内建函数format来实现百分比的数据输出. >>> print(format(0.5236, '.2%')) 其结果如 ...

  10. WPF 中的字号问题

    用WPF搞打印机真是各种碰壁,尤其是对于我这个没有搞过打印机的人来说,更是遍布神坑T_T. 今天敲代码的时候发现字体的FontSize貌似跟单位也有关系啊,因为打印的时候效果感觉和预期竟然是有着差距的 ...