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. js 替换 当前URL 特定参数

    js 替换 当前URL 特定参数 2012-12-24 20:45:53|  分类: JS&JQuery |举报 |字号 订阅   //替换指定传入参数的值,paramName为参数,repl ...

  2. C-指针和数组的区别

    指针的操作: 允许:1)同类型指针的赋值 2)与整形的加减运算 3)指向同一数组内指针的减运算和比较 4)赋 ‘0’ 或与 ‘0’ 比较 不允许:1)两指针的相加,相乘除,位移或mask 2)与flo ...

  3. WP8 学习 ApplicationBar 的创建 XAML代码

    phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar Opacity="0.1" IsVis ...

  4. IE11无法 登陆银行网站

    1,打开IE11,看着键盘,按住Alt+X,然后按字母O打开IE设置选项=>[安全]选项卡把安全级别拉到最下,关闭[启用保护模式] 2,点击[受信任的站点]将支付宝和农业银行网址添加进去,关闭选 ...

  5. fastboot 刷system.img 提示 sending 'system' (*KB)... FAILED (remote: data too large)

    华为G6-C00卡刷提示OEMSBL错误,只能线刷 ,但是官方找不到线刷img镜像,无奈 网上下了个可以线刷的工具套件 流氓ROM . 使用HuaweiUpdateExtractor(工具百度)把官方 ...

  6. python解无忧公主的数学时间编程题001.py

    python解无忧公主的数学时间编程题001.py """ python解无忧公主的数学时间编程题001.py http://mp.weixin.qq.com/s?__b ...

  7. Unichar, char, wchar_t

    之前总结了一些关于字符表示,以及字符串的知识. 现在在看看一些关于编译器支持的知识. L"" Prefix 几乎所有的编译器都支持L“” prefix,一个字符串如果带有L“”pr ...

  8. Listview之优化BaseAdapter中的getView中的contentView

    BaseAdapter中getView中改动的地方: @Override public View getView(int position, View contentView, ViewGroup a ...

  9. Non-constant Fields in Case Labels

    Non-constant Fields in Case Labels in android library project http://tools.android.com/tips/non-cons ...

  10. SVG 2D入门2 - 图形绘制

    基本形状 SVG提供了很多的基本形状,这些元素可以直接使用,这一点比canvas好多了.废话不说了,直接看例子,这个最直接:   <svg width="200" heigh ...