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 ...
随机推荐
- linux-虚拟机安装
第一步:下载 安装虚拟机! 链接: http://pan.baidu.com/s/1nuGLwsL 密码: 2qdy 第二步:镜像文件! 链接: http://pan.baidu.com/s/1nuG ...
- AngularJS 指令实践
概述 如果你写过AngularJS的应用,那么你一定已经使用过指令,不管你有没有意识到.你肯定已经用过简单的指令,比如 ng-mode, ng-repeat, ng-show等.这些指令都赋予DOM元 ...
- Operating System Concepts 项目:生产者-消费者问题 线程
一. 实验目的 实现一个c程序,该程序能模拟解决有限缓冲问题,其中消费者和生产者产生和消耗随机数 二.实验内容 缓冲区 元数据类型为buffer_item,大小为1000的数组,按环形队列处理 生产者 ...
- javascript 错误处理
try{ var date=new Date(); date.test();//调用date的未定义的test方法; document.wrire("try块执行结束<br>&q ...
- ubuntu下的第一个脚本file.sh
1.新建空文档,写入shell命令: #!/bin/sh cd /home/plg ./usb 第一行一定要有,一开始参考网上写的#!/usr/bin/sh,会提示错误 bash: ./file.sh ...
- 使用OCI向Oracle插入Geometry数据
使用C/C++操作Oracle数据库,使用OCI可谓是最强大,当然也是最难的方式.Oracle是一个功能复杂而强大的数据库,它可以很好的支持空间数据(Oracle spatial).如何使用OCI向O ...
- JavaScript之document对象使用
1.document 对象常用的有三种: A.document.getElementById:通过html元素的Id,来获取html对象.适用于单个的html元素. B.document.getEle ...
- iOS对象序列化
系统对象的归档我就不介绍了,这个不复杂,自己看一下就会了. 我在这里主要介绍自定义对象的归档. Sample.h文件 // // Sample.h // Serialization // // ...
- Jquery中的prop()方法 全选或全不选
注意: prop()在高版本才会有效, 低版本用attr(); $(function(){ // 元素checkbox var aChecked = $('.checkGoods'); // 全选 v ...
- JS 中的五个假值
1."", undefined, null, 0, NaN 除了这五个假值以外,其他所有值转布尔类型都是true.还有一个特殊的false.