Codeforces Round #297 (Div. 2)
A题
题目大意:
给你一个字符串,奇数的时候是钥匙,偶数的时候是门,一把钥匙只能开对应的门,然后问你最少额外需要多少把钥匙。
分析:
用的数组记录一下就行,(注意的是先开门,再拿钥匙!开始错在这里了,决心好好学英语)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
using namespace std;
int main()
{
int n,vist[];
char a[];
scanf("%d",&n);
scanf("%s",a);
memset(vist,,sizeof(vist));
vist[a[]-'a']=;
int sum=;
int i;
for( i=;i<*n-;i=i+)
{
if(vist[a[i]-'A']==)
{
sum++;
}
else
{
vist[a[i]-'A']--;
}
vist[a[i+]-'a']++;
}
printf("%d\n",sum);
return ;
}
B题
题目大意
一个字符串str ,从1 开始长度为s,每次给你一个 a[i] ,然后将 [ a[i] , (s-a[i]+1) ] 翻转,问你经过n次操作以后整个字符串是什么样的。
分析
需要从内到外,看那些区域需要翻转,那些区域不需要就行了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#define maxn 410004
using namespace std;
int vist[maxn],zhuan[maxn]; int main()
{
char a[];
int n,num;
scanf("%s",a);
int len=strlen(a);
memset(vist,,sizeof(vist));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&num);
vist[--num]++; }
int sum=;
for(int i=;i<len/;i++)
{
sum+=vist[i];
if(sum%)
swap(a[i],a[len-i-]);
}
printf("%s\n",a);
return ;
}
C题
题目大意
给出n条线段的长度,任意一条长度为len的线段可以当作len或len-1的线段使用,求能构成的矩形的最大的总面积(可以是多个矩形的和)。
分析
要是总面积最大,就要贪心,使长度最大的对子和长度次最大的对子组合,可以是多个矩形的和。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#define INF 10000000
using namespace std;
int main()
{
int n;
long long a[];
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);
sort(a+,a++n);
long long flag=;
long long ans =;
for(int i=n;i>;)
{
if(a[i]==a[i-]||a[i]-==a[i-])
{
if(flag)
{
ans+=flag*a[i-];
flag=;
}
else
flag=a[i-];
i=i-;
}
else
i--;
} printf("%I64d\n",ans);
return ;
}
D题
题目大意
给你一个n*m的格子,'.'代表空地,'*'代表墙,你使墙变为空地,问你最小的次数使每个空地块为矩形。
分析
每当搜索到有3个'.'的就让那个余下的变为空地,再次在它的四周8格以每4格搜索,直到都符合。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std; char a[][];
int n, m; bool check(int x, int y)
{
if(a[x][y] == '.' || x < || y < || x > n || y > m) return ; if(a[x][y - ] == '.' && a[x - ][y - ] == '.' && a[x - ][y] == '.') return ;
if(a[x][y + ] == '.' && a[x - ][y + ] == '.' && a[x - ][y] == '.') return ;
if(a[x][y - ] == '.' && a[x + ][y - ] == '.' && a[x + ][y] == '.') return ;
if(a[x][y + ] == '.' && a[x + ][y + ] == '.' && a[x + ][y] == '.') return ; return ;
}
int x[]= {-,-,,,,,,-};
int y[]= {,,,,,-,-,-};
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i <= n; i++)
{
scanf("%s", a[i] + );
} queue<pair<int , int> > q;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
if(check(i, j))
q.push(make_pair(i, j));
}
} while(!q.empty())
{
int i = q.front().first;
int j = q.front().second;
q.pop();
if(!check(i, j)) continue;
a[i][j] = '.';
for(int ii=; ii<; ii++)
{
if( check(i + x[ii], j + y[ii]))
{
q.push(make_pair(i + x[ii], j + y[ii]));
}
}
} for(int i = ; i <= n; i++)
{
printf("%s\n", a[i] + );
} return ;
}
Codeforces Round #297 (Div. 2)的更多相关文章
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- [Codeforces Round #297 Div. 2] E. Anya and Cubes
http://codeforces.com/contest/525/problem/E 学习了传说中的折半DFS/双向DFS 先搜前一半数,记录结果,然后再搜后一半数,匹配之前结果. #include ...
随机推荐
- 使用HTTP访问网络------使用HTTPURLConnection
HTTPURLConnection继承了URLConnection,因此也可用于向指定网站发送GET请求.POST请求.它在URLConnection的基础上提供了如下便捷的方法: 1.int ge ...
- 为什么你总是学不好Linux技术?这是我的答案。
摘要: 我们为什么要学习Linux,最近几年Linux发展迅速,特别服务器领域,带来了很多新技术,云计算,虚拟化,大数据等技术,还有安全方面都有了很大的发展同时也给了Linux运维工作带来了,更多的要 ...
- Debug的F5~F8用法
快捷键(F6)单步执行程序,遇到方法时跳过. 快捷键(F8)执行此断点到最后,进入下一个断点开始之处. 快捷键(F5)单步执行程序,遇到方法时进入. 快捷键(F7)单步执行程序,从当前方法跳出.
- Javascript arguments详解
今天我们来看看arguments对象及属性.arguments对象不能显式创建,arguments对象只有函数开始时才可用.函数的 arguments 对象并不是一个数组,访问单个参数的方式与访问数组 ...
- Mongoose 是什么?
Mongoose 参考手册 标签(空格分隔): MongoDB 一般我们不直接用MongoDB的函数来操作MongoDB数据库 Mongose就是一套操作MongoDB数据库的接口. Schema 一 ...
- Python标准库---子进程 (subprocess包)
这里的内容以Linux进程基础和Linux文本流为基础.subprocess包主要功能是执行外部的命令和程序.比如说,我需要使用wget下载文件.我在Python中调用wget程序.从这个意义上来说, ...
- IT公司100题-5-查找最小的k个元素
问题描述: 输入n 个整数,输出其中最小的k 个. 例如输入8, 7, 6, 5, 4, 3, 2, 1这8 个数字,则最小的3 个数字为3, 2, 1. 分析: 时间复杂度O(nlogn)方法: ...
- JavaScript 数组方法和属性
一. 数组对象的操作方法 1. 数组的创建 2.prototype属性 返回对象原型的引用,prototype属性时object共有的. objectName.prototype,其中objectNa ...
- Line计划今年全面进军中国市场:建立本地团队
北京时间6月13日下午消息,<华尔街日报>报道称,移动消息应用Line计划于今年晚些时候进军中国市场.Line将在中国建立本地团队,开发内容和功能,从而进一步开拓中国这一全球最大的移动市场 ...
- pager分页框架体会
<pg:pager> 元素的属性中: maxPageItems说的是每页偏移量是多少,这个并不是说每一页显示多少,而是第二页比第一页来说,在第一页的尾部增加多少,第一页又被覆盖多少,是决定 ...