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. Ajax的get请求向服务器请求数据五步骤?

    如下: ①创建ajax对象 ②建立http请求 ③发送http请求 ④设置ajax对象状态改变的回调函数 ⑤判断ajax状态是否等于4,做相应的业务逻辑

  2. php 递归 适合刚刚接解递归的人看

    递归,就是自己调用自己,当满足某条件时层层退出(后进先出). --------------------------------------------------------------------- ...

  3. mysql 修改字段长度

    mysql 修改字段长度 alter table news  modify column title varchar(130); alter table 表名 modify column 字段名 类型 ...

  4. FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框

    FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...

  5. Redux介绍及基本应用

    一.Redux介绍  Redux的设计思想很简单,就两句话: Web应用是一个状态机,神力与状态是一一对应的 所有的状态,保存在一个对象里面 二.Redux基本概念和API Store Store就是 ...

  6. c# equals和==的区别

    简言之: equals必须是类型和值都得相等 == 只要值相等 注意: void Main() { ; ; Console.WriteLine(a.Equals(b)); //True (short会 ...

  7. Why java main function is declared as static type?

    一个暂且说的过去的解释 The method is static because otherwise there would be ambiguity: which constructor shoul ...

  8. shell括号操作符

    以下以bash环境下做解说 一.单小括号() 二.双小括号(()) 可作数值条件操作,也可作数值运算使用(近似于 let 命令) 如 C 语言语法一样,支持运算符:<<.<<= ...

  9. Android之使用HTTP协议的Get/Post方式向服务器提交数据

    1.Get方式 方法:通过拼接url在url后添加相应的数据,如:http://172.22.35.112:8080/videonews/GetInfoServlet?title=霍比特人&t ...

  10. C#中的委托与事件

    1,委托? 通俗来讲,就是一个能存放符合某种格式(签名)的方法的指针 的容器  (可以将方法作为一个参数来传递到另一个方法内执行) 定义委托:delegate string DelegateSayHi ...