2010 Asia Fuzhou Regional Contest
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的更多相关文章
- 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 ...
- 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 ...
- HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 2011 Asia Fuzhou Regional Contest
Xiangqi http://acm.hdu.edu.cn/showproblem.php?pid=4121 模拟,用高内聚低耦合的思想来写模拟题还是很好的,提高了函数的可重用性,程序的可读性,正确性 ...
- HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang
感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...
随机推荐
- SublimeText快捷键大全(附GIF演示图)
Sublime Text是码农必备之神器,有助于码农快速开垦,如果掌握了Sublime强大的快捷键就可以飞起来了.下面下载吧小编汇总了SublimeText支持的全部快捷键(适用SublimeText ...
- FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框
FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...
- EMVTag系列11《电子现金发卡行授权码》
按照银联个人化模板的建议,如卡片支持非接触快速支付应用(qPBOC),则推荐将电子现金授权码(9F74)作为qPBOC 应用AFL列表中的最后一条记录,且最后一条记录仅包含该数据元. 原因是:在某些情 ...
- DB2中的转义字符
1.数据库脚本 )); ,'20%'); ,'OLIVER_QIN'); ,'AA''') 2.以下是DB2的转义字符 2.1 对“%”的转义 SELECT * FROM OLIVER_11 WHER ...
- hdu 1228 A + B
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1228 A + B Description 读入两个小于100的正整数A和B,计算A+B.需要注意的是: ...
- centos php-fpm nginx配置
移除旧的软件包:yum remove httpd* php* 安装:yum install php php-fpm yum install php-gd php-mysql php-mbstring ...
- SQLite之读取数据库内容
1.打开已有数据库. //打开数据库 - (BOOL )openDB {// 红色部分修改为自己的数据库路径 return (SQLITE_OK == sqlite3_open([@"/Us ...
- UIView的创建与内存管理
学习过程中遇到一些问题,现在记录下来,以后忘记以便翻看. 创建工程的步骤: xcode的ARC改为MRC .h文件中的strong改为retain .m文件中加入dealloc方法 .m文件中_win ...
- ListBox mvvm 学习笔记
1. ListBox MvvM 例子1. 简单的绑定,ItemsSource 绑定到一个实现了IEnumerable 的类上.一般该绑定都是双向的,所以优先考虑使用 ObservableCollec ...
- 6 让我们的C#程序开始做点数学运算
请相信我你只需要懂得最基本的数学运算,就可以从事大多数的软件项目的开发工作.千万不要一提编程,就让数学把你吓跑了.大多数的程序开发人员从事的编程工作是应用系统的开发.这些系统的绝大多数功能,只需要最基 ...