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. 四、MongoDB的查询

    一.MongoDB的下载.安装与部署 二.MongoDB的基础知识简介 三.MongoDB的创建.更新和删除 db.blogs.insert([ { "author": " ...

  2. C#高级功能(一)Lambda 表达式

    Lambda 表达式是一种可用于创建委托或表达式目录树类型的匿名函数. 通过使用 lambda 表达式,可以写入可作为参数传递或作为函数调用值返回的本地函数. Lambda 表达式对于编写 LINQ ...

  3. 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug

    场景:在用户通过支付通道支付完成返回时,发现我收到的处理数据记录中有两条同样的数据记录, 也就是同一笔钱,我数据库中记为了两条一样的记录. tornado端代码 from tornado import ...

  4. jpg图片在IE6、IE7和IE8下不显示解决办法

    坑人的IE浏览器,花了我一个小时才找到原因. 原因:IE内核不能渲染CMYK模式的jpg图片,需要转换为RGB模式. 在photoshop里点击菜单栏—图像—RGB模式就行了 引用:http://lg ...

  5. EMVTag系列9《卡片管理数据》

    Ø  5F30    服务码 F: n 3 T: 5F30 L: 2 -O(可选):可选数据元 按GB/T 17552标准,卡片中的服务码(5F30) 的值,要和二磁道等效数据57中的服务码的值完全一 ...

  6. struts2框架基本操作总结

    struts技术说明 一:第一配置开发环境 1.struts.xml文件 <?xml version="1.0" encoding="UTF-8" ?&g ...

  7. nginx 配置 ThinkPHP Rewrite

    server { listen 80; server_name www.funsion.com; root /www/web/funsion; index index.php; location / ...

  8. hdu 5199 Gunner

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... #include<algorithm> #include& ...

  9. ios中怎么样设置drawRect方法中绘图的位置

    其中drawRect方法中的参数rect就是用来设置位置的,

  10. 安装Ubuntu 15.10后要做的事

    Ubuntu 15.10发布了,带来了很多新特性,同样也依然带着很多不习惯的东西,所以装完系统后还要进行一系列的优化. 1.删除libreoffice libreoffice虽然是开源的,但是Java ...