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. GCC 警告提示的用法

    转自GCC 警告提示的用法 本节主要讲解GCC的警告提示功能.GCC包含完整的出错检查和警告提示功能,它们可以帮助Linux程序员写出更加专业和优美的代码.我们千万不能小瞧这些警告信息,在很多情况下, ...

  2. 浅谈 iOS 之 Crash log 符号化

    其实,对于做移动 APP 开发的同学来说,质量和体验都是同等重要的.一个 APP 应用如果经常「闪退」,是产品质量很差的一个体现,那么用户体验就更不用再提了. *** 上面是笔者截取的国外一家公司对用 ...

  3. Moloch

    http://www.oschina.net/p/moloch maltego http://www.oschina.net/p/maltego

  4. java 使用正则表达式从网页上提取网站标题

    如何从网页上抓取有价值的东西?看懂了下面的程序(非常简单),想从网页上抓取什么信息(标题.内容.Email.价格等)就能抓取什么信息. package catchhtml; import java.i ...

  5. ASP.NET MVC 入门3、Routing

    本系列文章基于Microsoft ASP.NET MVC Beta. 在一个route中,通过在大括号中放一个占位符来定义( { and } ).当解析URL的时候,符号"/"和& ...

  6. JS单击隐藏界面元素

    1. JS代码 <script type="text/javascript" language="javascript"> // function ...

  7. Android Integer.decode()和Intger.valueof()

    decode合适用来分析数字 可以分析 8进:010=>分析后为 8 10进:10=>分析后为 10 16进:#10|0X10|0x10=>分析后是 16 而valueof    只 ...

  8. 使用 jQuery.i18n.properties 实现 Web 前端的国际化

    jQuery.i18n.properties 简介 在介绍 jQuery.i18n.properties 之前,我们先来看一下什么是国际化.国际化英文单词为:Internationalization, ...

  9. linux,Centos,bash: service: command not found

    很简单,这个问题是这样的,su 或者 su root:的话只是将当前身份转为root,用户shell并没有改变.所以有些系统命令不能使用. su -或者su -l或者su -l root,可以完全的将 ...

  10. winhex的使用

    1. 当我们用VC编写代码,将数据写入到磁盘的文件后,用winhex查看,winhex可以检测文件最后写入时间的变动,如果有变动,则会提示“此文件的最后写入时间已经改变.解除当前状态并重新载入吗?”, ...