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 ...
随机推荐
- poj 1180:Batch Scheduling【斜率优化dp】
我会斜率优化了!这篇讲的超级棒https://blog.csdn.net/shiyongyang/article/details/78299894?readlog 首先列个n方递推,设sf是f的前缀和 ...
- bzoj 1709: [Usaco2007 Oct]Super Paintball超级弹珠【枚举】
k是1e5范围的,吗? 注意到n只有100,这意味着k去重之后之后n^2,也就是1e4! 然后就可以愉快的n^4枚举了,枚举每个格子,再枚举每个敌人,如果当前格子射不到敌人则退出,否则满足所有敌人则a ...
- 商品期货高频交易策略Tick框架
原帖地址:https://www.fmz.com/bbs-topic/1184在商品期货高频交易策略中, Tick行情的接收速度对策略的盈利结果有着决定性的影响,但市面上大多数交易框架,都是采用回调模 ...
- 2017杭电多校第六场1011Classes
传送门 Classes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- Android 性能优化(5)网络优化 (1) Collecting Network Traffic Data 用Network Traffic tool :收集传输数据
Collecting Network Traffic Data 1.This lesson teaches you to Tag Network Requests 标记网络类型 Configure a ...
- TensorFlow---基础---GFile
使用TensorFlow的时候经常遇到 tf.gfile.exists().... 关于gfile,一个googler是这样给出的解释: The main roles of the tf.gfile ...
- [转]MySQL存储过程
转自:http://www.cnblogs.com/exmyth/p/3303470.html 14.1.1 创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATE PROCEDURE ...
- git add . 的时候报错fatal: Unable to create : …File exists.
报错内容: $ git add . fatal: Unable to create 'E:/project/qbm_cs/.git/index.lock': File exists. Another ...
- js中true和false判断
布尔类型里只有这6参数个返回false,其它都为true Boolean(false) // false Boolean(undefined) // false Boolean(null) // fa ...
- MAMP中Python安装MySQLdb
Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Py ...