比赛链接:http://acm.hdu.edu.cn/diy/contest_show.php?cid=18010
problem1001
Meepo’s Problem I
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/65536K (Java/Other)
Total Submission(s) : 249 Accepted Submission(s) : 77
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
2012.11.11is Meepo's Mother's Grandmother's 1111th birthday(I don't know why= =), Meepo wants visit her, and there is an argument between two clones.
“Mother's Grandmother and Grandmother's Mother's are the same person.” one says.
“No, you're wrong......” other says.
“I'm right! Because Grandfather's father's and father's Grandfather are same person!” The first one says.
Meepo's clones are imperfect, so they don't know which one is right and ask for you to solve this problem.
Input
Then two string, s1 and s2, each one describes a person.
All string's length <= 10000.
String is only consisted of 6 elements :
1. 'A' : denote father.
2. 'B' : denote mother.
3. 'C' : denote grandmother.
4. 'D' : denote grandfather.
5. 'E' : denote maternal grandmother (mother's mother).
6. 'F' : denote maternal grandfather (mother's father).
Output
Sample Input
3 AD DA BC CA AB BA
Sample Output
YES NO NO
Author
#include
#include
#include
using namespace std;
#define MAX 20010
char str1[MAX];
char str2[MAX];
int st1[MAX];
int st2[MAX];
void solve(char str[MAX],int st[MAX])
{
int len=strlen(str);
int ct=1;
int i;
for(i=0;i
switch(str[i])
{
case 'A':
st[ct++]=0;
break;
case 'B':
st[ct++]=1;
break;
case 'C':
st[ct++]=0;
st[ct++]=1;
break;
case 'D':
st[ct++]=0;
st[ct++]=0;
break;
case 'E':
st[ct++]=1;
st[ct++]=1;
break;
case 'F':
st[ct++]=1;
st[ct++]=0;
break;
}
}
st[0]=ct-1;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
getchar();
scanf("%s%s",&str1,&str2);
solve(str1,st1);
solve(str2,st2);
int i;
if(st1[0]!=st2[0])
printf("NO\n");
else
{
bool flag=true;
for(i=1;i<=st1[0];i++)
{
if(st1[i]!=st2[i])
{
flag=false;
break;
}
}
if(flag==true)
{
printf("YES\n");
}
else
printf("NO\n");
}
}
}
Dota
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 73 Accepted Submission(s) : 36
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
n+1 lines. The first line is an integer n(1<=n<=100),which means there are n game equipements and n different players,both of them can be numbered
from 1 to n. Then fllowing 2th to (n+1)th line, each line contains n positive integers,the jth integer in the (i+1)th line means that the ith player
is willing to buy the jth equipement at this price.
Output
Sample Input
2 1 100 2 10 20 12 21
Sample Output
100 32
Author
Couple Game
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 302 Accepted Submission(s) : 53
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
(Hint:While submitting the code, choose the Microsoft Visual C++ compiler, or you might get an TLE.)
Input
Output
Sample Input
4 1 4 2 3 5 6 7 8
Sample Output
Yes
Author
#include
#include
#include
using namespace std;
#define MAX 200010
int st[MAX];
int match[MAX];
int n;
bool solve()
{
int head,tail;
head=tail=0;
st[tail++]=1;
int i;
for(i=2;i<=2*n;i++)
{
if(match[st[tail-1]]==i)
tail--;
else
st[tail++]=i;
}
if(head==tail)
return true;
return false;
}
int main()
{
while(scanf("%d",&n))
{
if(n==0)
break;
int i;
int a,b;
for(i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
match[a]=b;
match[b]=a;
}
if(solve())
{
printf("Yes\n");
}
else
printf("No\n");
}
}
//
栈的应用,开始的时候递归实现导致栈溢出.
problem 1005:
Crazy review
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 50 Accepted Submission(s) : 18
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
As we see, some courses are easy to learn, but hard to master, while others are not; For each course, if you spend one hour on it, the next hour Vi will increase Dvi ( | Dvi | <=10); if Vi+Dvi is negative, Vi will become zero and never change. In this condition, no matter how hard Sweetsc learn the course, his score will never rise.
Because of some reasons (absent , unfinished homework) , There is an upper bound score Ui for every course . If Sweetsc's score reach the upper bound , his score will be the upper bound and never rise.
To make the description more clear , There is a chart for Si = 30. Vi = 20, Dvi = -5 and Ui = 70
Time 0 1 2 3 4 5 6 7 8
Score 30 50 65 70 70 70 70 70 70
Vi 20 15 10 5 0 0 0 0 0
Write a program to help sweet to pass all exams (in other words , get >= 60 scores in all exams). If he will fail in one or more courses, just print “POOR SWEETSC” (without quote). Otherwise, find an optimal average score he can get (ROUND TO THE NEAREST INTEGER)
Input
Then following N lines. Each line include exactly 4 integers. Si,Vi,Dvi,and Ui.
Output
Round the average to the nearest integer.
Sample Input
2 5 10 30 -5 70 40 20 5 100
Sample Output
83
Author
#include
#include
using namespace std;
#define MAX 25
int v[MAX];
int s[MAX];
int d[MAX];
int u[MAX];
int sum[MAX][510];
int n,h;
int ans;
int tot;
void make()
{
int i,j;
for(i=1;i<=n;i++)
{
sum[i][0]=s[i];
for(j=1;j<=h;j++)
{
int add=v[i]+(j-1)*d[i];
if(add<0)
add=0;
sum[i][j]=sum[i][j-1]+add;
if(sum[i][j]>u[i])
sum[i][j]=u[i];
}
}
}
void dfs(int cur,int time)
{
if(cur==n+1)
{
if(tot>ans)
ans=tot;
return;
}
int i;
for(i=1;i<=h && i<=time;i++)
{
if(sum[cur][i]>=60)
{
tot+=sum[cur][i];
dfs(cur+1,time-i);
tot-=sum[cur][i];
}
if(sum[cur][i]>=u[cur])//note
break;
}
}
int main()
{
while(scanf("%d%d",&n,&h)!= EOF)
{
int i;
for(i=1;i<=n;i++)
{
scanf("%d%d%d%d",&s[i],&v[i],&d[i],&u[i]);
}
make();
ans=-1;
tot=0;
dfs(1,h);
if(ans!=-1)
printf("%d\n",(int)(ans*1.0/n+0.5));
else
printf("POOR SWEETSC\n");
}
}
//
传送装置
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 82 Accepted Submission(s) : 21
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
每组输入数据第一行包括3个整数n(1<=n<=100),m(0<=m<=n*n),s(1<=s<=n)。n 是地点的数目,m是传送路线的数目,s代表Sue所在寝室的编号,接下来m行每行3个整数 u, v, w,表示有一条不可逆的传送路线从u到v并且这条传送路线的能源值耗费是w(0
Output
Sample Input
5 7 1 1 4 2 4 5 3 5 1 1 5 3 1 1 2 1 2 3 4 3 1 3 3 3 1 1 2 1 2 3 4 3 2 5
Sample Output
3 Poor Sue
Author
#include
using namespace std;
#define MAX 10010
#define INFINITY 1000000000
int n,m;
struct edge
{
int cap;
int flow;
int ver;
edge*next;
edge*rev;
};
edge edges[2*MAX+1];
edge* link[MAX+1];
int dist[MAX +1];
int h[MAX + 1];
int num;
int total_flow;
int min(int a,int b){return a < b?a:b;};
void add(int start,int end,int c)
{
num++;
edges[num].ver = end;
edges[num].cap = c;
edges[num].next = link[start];
link[start] = edges + num;
num++;
edges[num].ver = start;
edges[num].cap = 0;
edges[num].next = link[end];
link[end] = edges + num;
link[start]->rev = link[end];
link[end]->rev = link[start];
}
int sap(int n,int src,int des)
{
edge* cur_edges[MAX+1];
edge* rev_path[MAX+1];
total_flow = 0;
int i;
for(i = 1; i <= n ;i++)
cur_edges[i] = link[i];
int argu_flow = INFINITY;
int u = src;
while(dist[src] < n)
{
if(u == des)
{
for(i = src; i != des;i = cur_edges[i]->ver)
argu_flow = min(argu_flow,cur_edges[i]->cap);
for(i = src; i != des ;i = cur_edges[i]->ver)
{
cur_edges[i]->cap -= argu_flow;
cur_edges[i]->rev->cap += argu_flow;
cur_edges[i]->flow += argu_flow;
cur_edges[i]->rev->flow -= argu_flow;
}
total_flow += argu_flow;
u = src;
}
edge* e;
for(e = cur_edges[u];e; e = e->next)
if(e->cap > 0 && dist[u] == dist[e->ver] + 1)
break;
if(e)
{
cur_edges[u] = e;
rev_path[e->ver] = e->rev;
u = e->ver;
}
else
{
if(--h[dist[u]] == 0)
break;
cur_edges[u] = link[u];
int mini_dist = n;
for(edge* e = link[u]; e; e = e->next)
if(e->cap > 0)
mini_dist = min(mini_dist,dist[e->ver]);
dist[u] = mini_dist + 1;
h[dist[u]]++;
if(u != src)
u = rev_path[u]->ver;
}
}
return total_flow;
}
void rev_bfs(int n,int src,int des)
{
int q[MAX + 1];
int head = 0;
int tail = 0;
for(int i = 1; i <= n; i++)
{
dist[i] = MAX;
h[i] = 0;
}
q[tail++] = des;
dist[des] = 0;
h[0] = 1;
int p;
while(tail != head)
{
p = q[head++];
for(edge* e = link[p];e;e = e->next)
{
if(dist[e->ver] != MAX ||e->rev->cap == 0)
continue;
dist[e->ver] = dist[p] + 1;
h[dist[e->ver]]++;
q[tail++] = e->ver;
}
}
}
int main()
{
int src,des;
while(cin>>n>>m>>src)
{
memset(link,0,sizeof(link));
num = 0;
int start,end,c;
int des=n+1;
while(m--)
{
cin>>start>>end>>c;
//add(start,end,c);
if(end!=src)
{
add(start,end,c);
}
else
add(start,des,c);
}
rev_bfs(n+1,src,des);
sap(n+1,src,des);
if(total_flow!=0)
printf("%d\n",total_flow);
else
printf("Poor Sue\n");
}
}
//
增加一个附加汇点,将指向源点的边转而指向汇点,然后求出最大流就是答案.