Codeforces Round #228 (Div. 2)
做codeforces以来题目最水的一次
A题:
题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值
sol: 简单数论题目,直接求所有数字的最大公约数即可
ps: 以前cf出过这道题目啊,出题人没救了 5分钟300人过
1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5 const int MAX = ;
6 int num[MAX];
7 int gcd(int a,int b)
8 {
9 return b==? a : gcd(b,a%b);
}
int main()
{
int n;
while(scanf("%d",&n)>)
{
for(int i=;i<n;i++) scanf("%d",&num[i]);
int ans=num[];
for(int i=;i<n;i++)
{
ans=gcd(ans,num[i]);
}
printf("%d\n",ans*n);
}
return ;
25 }
B题
题意:求网格中的‘#’是不是全部恰好属于某一个红十字
sol:直接模拟即可
1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5 const int MAX = ;
6 char map[MAX][MAX];
7 int vis[MAX][MAX];
8 int main()
9 {
int n;
while(scanf("%d",&n)>)
{
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
{
getchar();
for(int j=;j<n;j++)
scanf("%c",&map[i][j]);
}
for(int i=;i<n-;i++)
{
for(int j=;j<n-;j++)
{
if(map[i][j]=='#'&&!vis[i][j])
if(map[i-][j]=='#'&&!vis[i-][j])
if(map[i+][j]=='#'&&!vis[i+][j])
if(map[i][j-]=='#'&&!vis[i][j-])
if(map[i][j+]=='#'&&!vis[i][j+])
{
vis[i][j]=; vis[i-][j]=; vis[i+][j]=
vis[i][j+]=; vis[i][j-]=
}
}
}
int flag=;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
if(!vis[i][j]&&map[i][j]=='#')
flag=;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
46 }
C题:
给出一堆箱子,和每个箱子的power值(即每个箱子的上方最多能放的箱子) 经过叠放之后看最后最少剩下多少堆。
sol :很简单的贪心题目,wa了3次(怕死贪心了>_<) 很容易想到如果先从上向下叠放的话叠放一次重量加1只要找到能足以承担
该重量的即可,因此从小到大排个序然后顺着取就可以了。
1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5 const int MAX = +;
6 const int inf = 0x3f3f3f3f;
7 int num[MAX],use[MAX];
8 int main()
9 {
int n,ans,ret;
while(scanf("%d",&n)>)
{
ans=; int tot=;
for(int i=;i<n;i++) scanf("%d",&num[i]);
sort(num,num+n);
memset(use,,sizeof(use));
while(tot!=n)
{
int i;
for(i=;i<n;i++) if(!use[i])
{
use[i]=;
ans++;
tot++;
break;
}
ret=;
for(int j=i+;j<n;j++)
{
if(!use[j]&&num[j]>=ret&&num[j]>)
{
tot++;
use[j]=; ret++;
}
}
}
printf("%d\n",ans);
}
return ;
40 }
D:
给出点1与点2之间最短路径的总数构建一个图的邻接矩阵。
sol: 开始想把路径都构成长为2的,再一看k真么大果断超时。之后想到了二分,之后就没然后了.
这题主要是利用二分和二进制思想(其实都差不多)主要看怎么构图。具体见代码(参考别人的呵呵)。
1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<algorithm>
5 #include<cmath>
6 using namespace std;
7 #define INF 100000000
8 int k, dp[][], node;
9 int main()
{
memset(dp,,sizeof(dp));
scanf("%d", &k);
dp[][]=dp[][]=dp[][]=;
dp[][]=dp[][]=f[][]=;
for (int i=; i<=; i++)
{
if (i%!=) dp[i][i+]=dp[i][i+]=;
else dp[i][i+]=dp[i][i+]=;
}
for (int i=; i<=; i++)
f[i][i+]=;
for (int i=; i>=; i--)
if (k&(<<i)) node=(i+)*,dp[node][+i]=;
for (int i=; i<=; i++)
for (int j=; j<=; j++) if (dp[i][j]) dp[j][i]=;
printf("%d\n",);
for (int i=;i<=;i++)
{
for (int j=;j<=;j++)
if (dp[i][j]) printf("Y");
else printf("N");
printf("\n");
}
34 }
E题:
又是一个贪心题目。就是给好几堆排然后第一个人取上层的,第二个人取底层的求两个人都采取最优策略能得到分数的最大值
还以为是个dp题目,但是维数太高果断贪心,但是怎么维护最大值又成了卡人的地方,原来这个题只要对半取就可以了,因为可以这么想
假设某堆牌的中上层有一个数大那么第一个人一定会想尽办法先拿到它,同理如果在中下层那么第二个人又会想办法先拿到它,总之:只要是在中上层的第一个人一定能拿到
所以只要对半分就可以了,只要稍微处理下排数为奇数的即可
34 }
Codeforces Round #228 (Div. 2)的更多相关文章
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- Codeforces Round #228 (Div. 1)
今天学长给我们挂了一套Div.1的题,难受,好难啊. Problem A: 题目大意:给你n个数字,让你叠成n堆,每个数字上面的数的个数不能超过这个数,如 3 上面最多放三个数字 问你,最少能放几堆. ...
- Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈
C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path 构造
B. Fox and Minimal path 题目连接: http://codeforces.com/contest/388/problem/B Description Fox Ciel wants ...
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
A. Fox and Box Accumulation 题目连接: http://codeforces.com/contest/388/problem/A Description Fox Ciel h ...
- Codeforces Round #228 (Div. 1) 388B Fox and Minimal path
链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...
- Codeforces Round #228 (Div. 2) B. Fox and Cross
#include <iostream> #include <string> #include <vector> #include <algorithm> ...
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
#include <iostream> #include <algorithm> #include <vector> #include <numeric> ...
- Codeforces Round #228 (Div. 1) B
B. Fox and Minimal path time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- 栗染-git命令搭建简单的个人的网页
本来一个很简单的东西被自己搞了很久 可能是对于一个小白来说第一次认识到github的魅力吧,以前只是听别人说过用github搭建网站,听起来很厉害的样子,一直也没有尝试过,突然兴起今天去网上找一些教程 ...
- mycat重启报错Failed to connect to the Wrapper at port解决方法
报错信息 ERROR | wrapper | 2018/05/11 14:01:55 | Startup failed: Timed out waiting for a signal from the ...
- redis在linux环境下的安装与启动
定义 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted s ...
- 使用纯css鼠标移入效果,炫酷的旋转正方体
首先我们需要创建几个盒子 </div> <div class="wrap"> <div class="cube"> < ...
- DecorView 的创建
在Activity 的启动过程中,调用ActivityThread 的handleResumeActivity 方法时,先得到一个与Activity 关联的PhoneWindow 对象,然后通过Pho ...
- 三维重建PCL:点云单侧面正射投影
终于把点云单侧面投影正射投影的代码写完了,为一个阶段,主要使用平面插值方法,且只以XOY平面作为的正射投影面.有些凑合的地方,待改进. 方法思路:使用Mesh模型,对每一个表面进行表面重建.借助Ope ...
- Markdown(github)语法
<< 访问 Wow!Ubuntu NOTE: This is Simplelified Chinese Edition Document of Markdown Syntax. If yo ...
- Container Views
https://developer.apple.com/documentation/uikit/views_and_controls Container Views Organize and pres ...
- CAD使用GetxDataDouble读数据(网页版)
主要用到函数说明: MxDrawEntity::GetxDataDouble2 读取一个Double扩展数据,详细说明如下: 参数 说明 [in] LONG lItem 该值所在位置 [out, re ...
- Oracle RAC 后台进程
LMS - Gobal 全局缓存服务进程 LMD - Global Enqueue Service Daemon 全局查询服务守护进程 LMON - 全局服务器监控进程 LCK0 ...