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 ...
随机推荐
- 清北考前刷题day5早安
/* C(n,k) */ #include<iostream> #include<cstdio> #include<cstring> #define ll long ...
- codechef: ADAROKS2 ,Ada Rooks 2
又是道原题... (HDU 6313 Hack It , 多校 ACM 里面的题) 题目说构造一个 n * n 矩阵,染色点不得构成矩形...然后染色点个数至少 8 * n 然后我们生成一个数 m , ...
- 洛谷2019 3月月赛 T2
题干 洛谷同款 T2?(看似比T1简单些) 二维前缀和嘛?[多简单 我天天拿二维前缀和水DP] 这是前缀和的预处理 2333 处理出来所有的情况 某个地方要加上mod再%mod 如果没有这一步 那么 ...
- xshell、xftp最新版下载方法
https://www.netsarang.com/download/main.html 登录邮箱打开第一个下载地址进行下载
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Overlapping Rectangles
There are nn rectangles on the plane. The problem is to find the area of the union of these rectangl ...
- Android 性能优化(9)网络优化( 5)Optimizing Server-Initiated Network Use
Optimizing Server-Initiated Network Use This lesson teaches you to Send Server Updates with GCM Netw ...
- 使用wkwebview后,页面返回不刷新的问题
onpageshow 事件在用户浏览网页时触发. onpageshow 事件类似于 onload 事件,onload 事件在页面第一次加载时触发, onpageshow 事件在每次加载页面时触发,即 ...
- SQL优化器简介
文章导读: 什么是RBO? 什么是CBO? 我们在工作中经常会听到这样的声音:"SQL查询慢?你给数据库加个索引啊".虽然加索引并不一定能解决问题,但是这初步的体现了SQL优化的思 ...
- Mybatis 在 insert 之后想获取自增的主键 id,但却总是返回1
记录一次傻逼的问题, 自己把自己蠢哭:Mybatis 在 insert 之后想获取自增的主键 id,但却总是返回1 错误说明: 返回的1是影响的行数,并不是自增的主键id: 想要获取自增主键id,需要 ...
- SQL server 上机练习题
首先创建一个数据库,里面有 登录表 学生表 课程表 选课表 成绩表 1. 查询Student表中的所有记录的Sname.Ssex和Class列.2. 查询教师所有的单位即不重复的Depart列 ...