HDOJ 5090

水题。从小到大排序,能够填充达到符合条件的。先填充好。填充之后进行调整。

传送门:

pid=5090">点击打开链接

#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e2+10;
int t, n, k, ia[MAXN]; int main()
{
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &k);
bool flag = true;
for(int i=1; i<=n; ++i)
{
scanf("%d", ia+i);
}
sort(ia+1, ia+n+1);
for(int i=1; i<=n; ++i)
{
if(i < ia[i])
{
flag = false;
break;
}
if(i == ia[i])
{
continue;
}
if(0 == (i-ia[i])%k)
{
ia[i] = i;
}
else
{
int tp = 1;
for(int j=i+1; j<=n; ++j)
{
if(0 == (j-ia[i])%k)
{
ia[i] = j;
tp = 0;
--i;
break;
}
}
if(tp)
{
flag = false;
break;
}
}
sort(ia+1, ia+n+1);
}
printf("%s\n", flag ? "Jerry" : "Tom");
}
return 0;
}

HDOJ 5092

题意:每行取一个数。使总和最小,取了mp[i][j]之后,仅仅能在该点左下,正下。右下三个位置里面取下一个点。记录路径。要注意尽量靠右。

分析:一个典型的dp

传送门:点击打开链接

#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e2+10;
const int INF = 0x7fffffff;
int t, m, n, dp[MAXN][MAXN];
int s[MAXN][MAXN], mp[MAXN][MAXN], icase = 1; void output(int i, int j)
{
if(0 == i)
{
return ;
}
if(1 == s[i][j])
{
output(i-1, j-1);
printf("%d ", j-1);
}
else if(2 == s[i][j])
{
output(i-1, j);
printf("%d ", j);
}
else if(3 == s[i][j])
{
output(i-1, j+1);
printf("%d ", j+1);
}
} int main()
{
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &m);
memset(dp, 0, sizeof(dp));
memset(mp, 0, sizeof(mp));
memset(s, 0, sizeof(s));
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=m; ++j)
{
scanf("%d", &mp[i][j]);
}
}
for(int i=1; i<=m; ++i)
{
dp[1][i] = mp[1][i];
}
for(int i=2; i<=n; ++i)
{
for(int j=1; j<=m; ++j)
{
int mn = INF;
if(j>=2 && dp[i-1][j-1] <= mn)
{
mn = dp[i-1][j-1];
s[i][j] = 1;
}
if(dp[i-1][j] <= mn)
{
mn = dp[i-1][j];
s[i][j] = 2;
}
if(j<=m-1 && dp[i-1][j+1] <= mn)
{
mn = dp[i-1][j+1];
s[i][j] = 3;
}
dp[i][j] = mn + mp[i][j];
}
}
int mn = INF, id = 0;
for(int i=1; i<=m; ++i)
{
if(dp[n][i] <= mn)
{
mn = dp[n][i];
id = i;
}
}
/*
printf("%d\n", mn);
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=m; ++j)
{
printf("%d ", dp[i][j]);
}
printf("\n");
}
*/
printf("Case %d\n", icase++);
output(n, id);
printf("%d\n", id);
}
return 0;
}

HDOJ 5093

分析:二分图。

队友写的,没细看,贴个队友的代码。之后有空再看。

传送门:

pid=5093">点击打开链接

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int match[1260];
char map[60][60];
int pic[1260][60];
int vis[1260];
int m,n;
int nx=0,ny[60],nk=0,flag=0,yvis[60];
int dp(int now)
{
int i;
for(i=0;pic[now][i]!=-1;i++)
{
int t=pic[now][i];
if(vis[t]==1)
continue;
vis[t]=1;
if(match[t]==-1||dp(match[t]))
{
match[t]=now;
return 1;
}
}
return 0;
}
int main()
{
//freopen("D:\\in.txt","r",stdin);
int t,i,j;
cin>>t;
while(t--)
{
cin>>m>>n;
for(i=0;i<m;i++)
scanf("%s",map[i]);
memset(yvis,0,sizeof(yvis));
for(i=0;i<n;i++)
ny[i]=i;
nx=nk=0;
flag=0;
memset(pic,-1,sizeof(pic));
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(map[i][j]=='*')
{
yvis[j]=1;
pic[nx][flag++]=ny[j];
}
if(map[i][j]=='#')
{
if(flag)
{
nx++;
flag=0;
}
if(yvis[j])
{
ny[j]=n+nk;
nk++;
yvis[j]=0;
}
}
}
if(flag)
{
nx++;
flag=0;
}
}
int ans=0;
memset(match,-1,sizeof(match));
for(i=0;i<=nx;i++)
{
memset(vis,0,sizeof(vis));
if(dp(i))
ans++;
}
cout<<ans<<endl;
}
}

HDOJ 5094

分析:BFS+状压(不然会MLE)。wa点:一个位置可能有几把不同的钥匙。

传送门:点击打开链接

#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 55;
int n, m, p, k, s, mk[MAXN][MAXN];
int vis[1<<11][MAXN][MAXN];
int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
struct P
{
int x, y, time, key;
};
map<int, int> mp; int BFS()
{
memset(vis, 0, sizeof(vis));
queue<P> que;
P s; s.x = s.y = 1;
s.key = s.time = 0;
if(mk[s.x][s.y])
{
s.key = mk[s.x][s.y];
}
vis[s.key][s.x][s.y] = 1;
que.push(s);
while(!que.empty())
{
P u = que.front();
que.pop();
if(u.x==n && u.y==m)
{
return u.time;
}
for(int i=0; i<4; ++i)
{
P v;
v.x = u.x + dir[i][0];
v.y = u.y + dir[i][1];
if(v.x<1 || v.x>n || v.y<1 || v.y>m)
{
continue;
}
int q = 51*51*51*u.x + 51*51*u.y + 51*v.x + v.y;
int tp = mp[q];
if(4e8 == tp)
{
continue;
}
if(0 == tp)
{
v.time = u.time + 1;
v.key = u.key;
if(mk[v.x][v.y] && 0==(mk[v.x][v.y]&u.key))
{
v.key += mk[v.x][v.y];
}
if(vis[v.key][v.x][v.y])
{
continue;
}
vis[v.key][v.x][v.y] = 1;
que.push(v);
}
else
{
if(u.key & (1<<tp))
{
v.time = u.time + 1;
v.key = u.key;
if(mk[v.x][v.y] && 0==(mk[v.x][v.y]&u.key))
{
v.key += mk[v.x][v.y];
}
if(vis[v.key][v.x][v.y])
{
continue;
}
vis[v.key][v.x][v.y] = 1;
que.push(v);
}
}
// printf("%d %d %d %d\n", v.x, v.y, v.time, v.key);
}
}
return -1;
} int main()
{
while(~scanf("%d%d%d", &n, &m, &p))
{
scanf("%d", &k);
mp.clear();
memset(mk, 0, sizeof(mk));
while(k--)
{
int ux, uy, vx, vy, g, hx, hy;
scanf("%d%d%d%d%d", &ux, &uy, &vx, &vy, &g);
hx = 51*51*51*ux + 51*51*uy + 51*vx + vy;
hy = 51*51*51*vx + 51*51*vy + 51*ux + uy;
if(0 == g) g = 4e8;
mp[hx] = mp[hy] = g;
}
scanf("%d", &s);
while(s--)
{
int x, y, q;
scanf("%d%d%d", &x, &y, &q);
mk[x][y] += (1<<q);
}
printf("%d\n", BFS());
}
return 0;
}

HDOJ 5095

分析:水题,写的时候注意处理-1,0。1就差点儿相同了。还有首位为正。不须要+。

传送门:点击打开链接

代码:

#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long lint;
const int MAXN = 20;
char ch[] = {'p', 'q', 'r', 'u', 'v', 'w', 'x', 'y', 'z'};
int ia[MAXN], t; int main()
{
scanf("%d", &t);
while(t--)
{
for(int i=0; i<10; ++i)
{
scanf("%d", ia+i);
}
int first = 1, zero = 1;
for(int i=0; i<10; ++i)
{
if(0 == ia[i])
{
continue;
}
zero = 0;
if(ia[i] < 0)
{
if(-1 == ia[i])
{
if(i < 9)
{
printf("-");
}
else
{
printf("-1");
}
}
else
{
printf("%d", ia[i]);
}
first = 0;
}
else
{
if(1 == ia[i])
{
if(!first)
{
printf("+");
}
first = 0;
if(i == 9)
{
printf("1");
}
}
else
{
if(!first)
{
printf("+");
}
first = 0;
printf("%d", ia[i]);
}
}
if(i < 9)
{
printf("%c", ch[i]);
}
}
if(zero) printf("0");
printf("\n");
}
return 0;
}

HDOJ 5098

队友写的,贴个代码。之后补。

传送门:点击打开链接

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
char info[1010][1030];
int need[1010][1010],nn[1010];
int num[1010];
int res[1010],ns; //ns为软件数量,res表示是否要重新启动
map<string,int> list;
int dfs(int now)
{
if(num[now]!=-1)
return num[now];
int ma=0,i;
for(i=0;need[now][i]!=-1;i++)
{
int t=need[now][i];
if(res[t])
ma=max(ma,dfs(t)+1);
else
ma=max(ma,dfs(t));
}
num[now]=ma;
return num[now];
}
int main()
{
//freopen("D:\\in.txt","r",stdin);
int t,i,j,count=1;
cin>>t;
getchar();
getchar();
while(t--)
{
memset(info,0,sizeof(info));
list.clear();
memset(res,0,sizeof(res));
i=0;
while(gets(info[i])) //開始数据处理
{
if(strlen(info[i])==0)
break;
j=0;
while(info[i][j]!='*'&&info[i][j]!=':')
j++;
list[string(info[i],j)]=i;
if(info[i][j]=='*')
res[i]=1;
i++;
}
ns=i;
memset(need,-1,sizeof(need));
memset(nn,0,sizeof(nn));
for(i=0;i<ns;i++)
{
int s=0;
while(info[i][s]!=' '&&s!=strlen(info[i]))
s++;
int e=s;
while(e!=strlen(info[i]))
{
s=e;
e++;
while(e!=strlen(info[i])&&info[i][e]!=' ')
e++;
need[i][nn[i]++]=list[string(info[i]+s+1,e-s-1)];
}
} //数据处理结束。need[i]表示i的依赖包,到-1结束
memset(num,-1,sizeof(num));
int ma=0;
for(i=0;i<ns;i++)
{
if(res[i])
ma=max(ma,dfs(i)+1);
else
ma=max(ma,dfs(i));
}
printf("Case %d: %d\n",count++,ma);
}
}

HDOJ 5099

分析:水题,字符串比較。

传送门:

pid=5099">点击打开链接

代码:

#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 2e3+10;
char cha[MAXN], chb[MAXN];
int t, icase = 1; int main()
{
scanf("%d", &t);
while(t--)
{
scanf("%s%s", cha, chb);
// puts(cha); puts(chb);
printf("Case %d: ", icase++);
if(cha[0] > chb[0])
{
printf("> ");
}
else if(cha[0] < chb[0])
{
printf("< ");
}
else
{
printf("= ");
}
if(cha[1] != chb[1])
{
cha[5] = chb[5] = '\0';
}
int ret = strcmp(cha+2, chb+2);
if(ret > 0)
{
printf(">");
}
else if(ret < 0)
{
printf("<");
}
else
{
printf("=");
}
printf("\n");
}
return 0;
}

2014上海全国邀请赛题解 HDOJ 5090-5099的更多相关文章

  1. 2014湘潭全国邀请赛I题 Intervals /POJ 3680 / 在限制次数下取有权区间使权最大/小问题(费用流)

    先说POJ3680:给n个有权(权<10w)开区间(n<200),(区间最多数到10w)保证数轴上所有数最多被覆盖k次的情况下要求总权最大,输出最大权. 思路:       限制的处理:s ...

  2. HDOJ 5090 Game with Pearls 二分图匹配

    简单的二分图匹配: 每个位置可以边到这些数字甚至可以边 Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  3. UVA LA 7146 2014上海亚洲赛(贪心)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...

  4. 贪心 HDOJ 5090 Game with Pearls

    题目传送门 /* 题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加, 问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom. 贪心:保存可能变成 ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)

    Seam Carving DescriptionFish likes to take photo with his friends. Several days ago, he found that s ...

  7. HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)

    Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...

  8. HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)

    Comparison of Android versionsProblem DescriptionAs an Android developer, itˇs really not easy to fi ...

  9. HDU5090——Game with Pearls(匈牙利算法|贪心)(2014上海邀请赛重现)

    Game with Pearls Problem DescriptionTom and Jerry are playing a game with tubes and pearls. The rule ...

随机推荐

  1. Mpeg-2的同步及时间恢复--STC,PCR,DTS,PTS

    http://blog.csdn.net/hice1226/article/details/6717354 Mpeg-2的同步及时间恢复--STC,PCR,DTS,PTS 摘要:Mpeg-2同步及时间 ...

  2. javaweb学习总结(四十)——编写自己的JDBC框架

    一.元数据介绍 元数据指的是"数据库"."表"."列"的定义信息. 1.1.DataBaseMetaData元数据 Connection.g ...

  3. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow(flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter)

    一. 1.Wiring a flow executor <flow:flow-executor id="flowExecutor" /> Although the fl ...

  4. MinGW 编译libwebsockets

    libwebsockets是一个轻量的纯C库,在这里尝试使用MinGW进行构建. 官网地址:http://libwebsockets.org/trac/libwebsockets下载地址:http:/ ...

  5. RxJava开发精要4 – Observables过滤

    原文出自<RxJava Essentials> 原文作者 : Ivan Morgillo 译文出自 : 开发技术前线 www.devtf.cn 转载声明: 本译文已授权开发者头条享有独家转 ...

  6. Spring AOP实现方式三【附源码】

    注解AOP实现 源码结构: 1.首先我们新建一个接口,love 谈恋爱接口. package com.spring.aop; /** * 谈恋爱接口 * * @author Administrator ...

  7. 转载:10个实用的但偏执的Java编程技术

    在沉浸于编码一段时间以后(比如说我已经投入近20年左右的时间在程序上了),你会渐渐对这些东西习以为常.因为,你知道的…… 任何事情有可能出错,没错,的确如此. 这就是为什么我们要采用“防御性编程”,即 ...

  8. Response.Write用法总结

    问题一: Response.Write 后连接Response.Redirect ,则Response.Write无法显示,直接跳转入Response.Redirect 的页面. 解决方案: Resp ...

  9. BZOJ3585: mex

    3585: mex Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 322  Solved: 169[Submit][Status] Descripti ...

  10. (5)I2C总线的10bit地址以及通用广播地址

    其实,10bit地址我没用过,通用广播地址更没用过.通用广播地址应该是在多个mcu之间用i2c进行通信时使用的.虽说没用到,但还是做了翻译,说不定以后有机会用到: 10bit地址 10bit的寻址扩展 ...