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. WordPress 撰写文章页面显示所有标签

    WordPress 撰写文章时,点击"从常用标签中选择"只显示45个常用的标签,很多情况下还需手工再次输入标签,这样的限制感觉很不方便,通过下面的方法可以解除这个限制,显示全部标签 ...

  2. Apache 多端口多站点配置实例

    分享下Apache多端口多站点的配置方法,配置apache服务器的朋友参考下. 配置httpd.conf 监听多个端口 复制代码代码如下: # Listen: Allows you to bind A ...

  3. IntelliJ IDEA 13破解(JRebel 5.6.3a破解)

    首先安装IntelliJ 13,记得要下载Ultimate Edition版本,不然就不需要破解了.. 安装到本地,然后进行一些配置(这一步可以不要,但是考虑到以后换系统可以省事,推荐做) 打开{in ...

  4. 解决vmware安装 win7 后 没有虚拟网卡驱动 不能上网的问题

    项目需要用到win7 32位系统,于是装个虚拟机,换了好几个系统资源,都是没有网卡驱动, XP 2003 都能上网唯独WIN7 不行,安装vmware tools也不管用,终于找到了这个东西.vmwa ...

  5. C#读取和写入配置文件

    使用.Net2.0中的ConfigurationManager可以方便的实现对配置app.config的读取和写入. ConfigurationManager默认没有自动载入项目,使用前必须手动添加, ...

  6. Oracle表变化趋势追踪记录

    #DBA_HIST_SEG_STAT可以看出对象的使用趋势,构造如下SQL查询出每个时间段内数据库对象的增长量,其中DB_BLOCK_CHANGES_DELTA为块个数 select c.SNAP_I ...

  7. vim之旅

    本人是今年的毕业生, 大学很莫名的选择了一个电子商务专业. 由于专业没有实质性的东西可学,加上对电商不敢兴趣, 于是乎我有了大量的时间在宿舍里折腾电脑. 折腾了几年大三决定转业, 大四在还没找工作之前 ...

  8. 7.css盒模型

    所谓的盒模型,其实就是把元素当成盒子,元素里的文本就是盒子里的东西. 而根据元素的特效,其盒模型的特效也不同,下面是一些总结: 1.块级元素(区块) 所谓块级元素,就是能够设置元素尺寸.有隔离其他元素 ...

  9. selenium+python cooking用法 (转)

    selenium-webdriver(python)--cookie处理 driver.get_cookies() 获得cookie信息 add_cookie(cookie_dict)  向cooki ...

  10. 如何在windows下安装python第三方包

    python安装第三方库一般方式和easy_install方式 2010-06-24 17:43:53|  分类: Python |  标签:python  |字号 订阅     python安装第三 ...