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. Tomcat 系统架构与设计模式,第 1 部分: 工作原理

    简介: 这个分为两个部分的系列文章将研究 Apache Tomcat 的系统架构以及其运用的很多经典设计模式.本文是第 1 部分,将主要从 Tomcat 如何分发请求.如何处理多用户同时请求,还有它的 ...

  2. [OJ] Data Stream Median (Hard)

    LintCode 81. Data Stream Median (Hard) 思路: 用一个大根堆保存较小的一半数, 一个小根堆保存较大的一半数. 每次根据num和两个堆顶的数据决定往哪个堆里面放. ...

  3. hihocoder #1290 : Demo Day (2016微软编程测试第三题)

    #1290 : Demo Day 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You work as an intern at a robotics startup. ...

  4. hdu4655Cut Pieces

    http://acm.hdu.edu.cn/showproblem.php?pid=4655 先以最大的来算为 N*所有的排列数  再减掉重复的 重复的计算方法:取相邻的两个数的最小值再与它前面的组合 ...

  5. [FOJ 1752] A^B mod C

    Problem 1752 A^B mod C Accept: 750    Submit: 3205Time Limit: 1000 mSec    Memory Limit : 32768 KB   ...

  6. ☀【CSS3】切换开关

    采用纯 CSS3 制作 iPhone 风格切换开关 √http://5m3d.com/?p=846 <!DOCTYPE html> <html lang="zh-CN&qu ...

  7. Ubuntu 安装Chrome步骤

    一.添加PPA 从Google Linux Repository(http://www.google.com/linuxrepositories/)下载安装Key,或把下面的代码复制进终端,回车,需要 ...

  8. 安全delete,添加refenerce,release

    #ifndef SAFE_ADDREF#define SAFE_ADDREF(p)    if (p != NULL) { p->AddRef(); }#endif #ifndef SAFE_R ...

  9. NEsper z

    对实时信息分析和处理,常常需要客户应用程序的开发相应功能.一般地,这些功能需要提供以下的处理流程,分析获取的数据,筛选数据,提取出有用的信息,然后将其通过特定的形式展现出来.由于具体实时信息的高并发性 ...

  10. WPF学习小记

    WPF通用控制事件 Click:当控件被单击时发生.某些情况下,当用户按下Enter键时也会发生这样的事件. Drop:当拖曳操作完成时发生,也就是说,当用户将某个对象拖曳dao该控件上,然后松开鼠标 ...