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. 图文详解如何搭建Windows的Android C++开发环境

    原地址:http://www.apkbus.com/android-18595-1-1.html //================================================= ...

  2. JNI|在子线程中获得JNIEnv|AttachCurrentThread

    A JNI interface pointer (JNIEnv*) is passed as an argument for each native function mapped to a Java ...

  3. 告别山寨数据线:USB Type-C加密认证出炉

    从去年苹果发布的MacBook首次采用USB Type-C接口开始,这一标准逐渐成为主流,许多旗舰手机慢慢地采用了这种接口.今日,非盈利机构USB开发者论坛(USB-IF)宣布了USB Type-C认 ...

  4. altium6.x中自动删除重复走线的位置

    在protel 2004 DXP中,“自动删除走线”的位置就在"PCB Editor"的默认页面,非常好找. 但是升级到了altium 6.7,6.9之后,很多人就找不到这个了. ...

  5. springboot 配置多数据源

    1.首先在创建应用对象时引入autoConfig package com; import org.springframework.boot.SpringApplication; import org. ...

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

    自动代理模式[和我们说的方式一 配置 和 测试调用不一样哦~~~]  纯POJO切面 源码结构: 1.首先我们新建一个接口,love 谈恋爱接口. package com.spring.aop; /* ...

  7. hduAnother Graph Game

    http://acm.hdu.edu.cn/showproblem.php?pid=4647 很扯的一题 将每条边的一半权值分给它所连的两个结点 #include <iostream> # ...

  8. CodeForces 400

    A - Inna and Choose Options Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  9. oracle的exp、imp命令

    1.EXP a>完全模式 full=y EXP USER/PASSWORD@DB (AS ROLE) BUFFER=64000 FILE=C:\FULL.DMP FULL=Y b>用户模式 ...

  10. spring--处理器拦截器详解——跟着开涛学SpringMVC

    5.1.处理器拦截器简介 Spring Web MVC的处理器拦截器(如无特殊说明,下文所说的拦截器即处理器拦截器) 类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理. ...