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)的更多相关文章

  1. 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  ...

  2. 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 ...

  3. 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  ...

  4. 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 ...

  5. 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  ...

  6. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...

  7. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  8. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  9. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  10. [Codeforces Round #297 Div. 2] E. Anya and Cubes

    http://codeforces.com/contest/525/problem/E 学习了传说中的折半DFS/双向DFS 先搜前一半数,记录结果,然后再搜后一半数,匹配之前结果. #include ...

随机推荐

  1. Ubuntu 查看/修改文件编码

    使用enca工具可以查看和修改文件编码 1.安装 sudo apt-get install enca 2.使用 查看文件编码 enca –L zh_CN file_name 修改文件编码 enca – ...

  2. 发送广播BroadcastReceiver

    import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.vi ...

  3. ASP.NET MVC 输出字符串

    @{Output.Write("<h1>输出字符串</h1>");}

  4. 电Call记录统计查询sql

    DECLARE @startTime datetimeset @startTime='2016-07-12' SELECT * FROM (--坐席号/电话个数/通话总时长select zuoxi a ...

  5. 带你揭开ATM的神秘面纱

    相信大家都用过ATM取过money吧,但是有多少人真正是了解ATM的呢?相信除了ATM从业者外了解的人寥寥无几吧,鄙人作为一个从事ATM软件开发的伪专业人士就站在我的角度为大家揭开ATM的神秘面纱吧. ...

  6. WEKA使用教程(界面工具的用法)

    WEKA使用教程 目录 1. 简介2. 数据格式3.数据准备4. 关联规则(购物篮分析)5. 分类与回归6. 聚类分析 1. 简介 WEKA的全名是怀卡托智能分析环境(Waikato Environm ...

  7. javascript作用域(Scope),简述上下文(context)和作用域的定义

    网页制作Webjx文章简介:这篇文章将正面解决这个问题:简述上下文(context)和作用域的定义,分析可以让我们掌控上下文的两种方法,最后深入一种高效的方案,它能有效解决我所碰到的90%的问题. 作 ...

  8. Android 应用按两下返回键退出应用程序

    在android应用开发中,有时候应用会用到按两下返回键退出应用的功能,今天介绍一下这个功能,直接上代码: @Override public boolean dispatchKeyEvent(KeyE ...

  9. Visual Studio Ultimate 2013 with Update 4

    Visual Studio Ultimate 2013 with Update 4 是一个先进的开发解决方案,各种规模的团队通过它均可设计和创建引人注目的应用程序,使用户兴致勃勃. Visual St ...

  10. SharePoint 2013 开发——开发并部署第一个APP

    博客地址:http://blog.csdn.net/FoxDave 本篇我们开始对开发APP应用程序进行了解. 本篇基于本地SharePoint环境(如果是Office 365的话会方便许多),需 ...