CodeForces_#354_Div.2_2016.5.25(A+B+C)
A
描述:给出一串数,可以互换任意两个数的位置一次,求最大的数和最小的数的最大距离.
分析:找到最大的数和最小的数的位置,求右边的数到左端点的距离和左边的数到右端点的距离.
#include <bits/stdc++.h>
using namespace std; const int maxn=+,INF=0x7fffffff;
int n,M1,M2,m1,m2;
int a[maxn]; int main(){
scanf("%d",&n);
M1=INF,M2=-INF;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<M1) M1=a[i], m1=i;
if(a[i]>M2) M2=a[i], m2=i;
}
if(m1>m2) swap(m1,m2);
int ans=max(n-m1,m2-);
printf("%d\n",ans);
}
B(模拟)
描述:酒杯落在一起,长得和数字三角形一样,每分钟倒一杯酒,满了会向两边流且流得一样多,问t分钟后有多少酒杯满了.
分析:模拟,一次性倒t杯酒(我sb地一杯一杯倒...TLE了好久).
#include <bits/stdc++.h>
using namespace std; const int maxn=+;
int n,t;
double a[maxn*maxn]; int main(){
scanf("%d%d",&n,&t);
a[]=t;
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++){
int x=(i-)*i/+j;
if(a[x]>=){
ans++;
a[(i*i+i)/+j]+=(a[x]-)/;
a[(i*i+i)/+j+]+=(a[x]-)/;
}
}
printf("%d\n",ans);
return ;
}
C(尺取法)
描述:给出一个由a,b组成的字符串,最多能改变k个字符,问最多有多少相同的字符串连在一起.
分析:尺取法.注意k=0的情况.
#include <bits/stdc++.h>
using namespace std; const int maxn=+;
int n,k;
int a[maxn]; void solve(){
int l=,r=,rem=k,ans=;
while(l<=n&&r<=n){
if(a[r]==){
while(rem==&&l<r)
if(a[l++]==) rem++;
if(rem) rem--;
else { l++; r++; continue; }
}
ans=max(ans,r-l+);
r++;
}
l=; r=; rem=k;
while(l<=n&&r<=n){
if(a[r]==){
while(rem==&&l<r)
if(a[l++]==) rem++;
if(rem) rem--;
else { l++; r++; continue; }
}
ans=max(ans,r-l+);
r++;
}
printf("%d\n",ans);
}
void init(){
scanf("%d%d\n",&n,&k);
for(int i=;i<=n;i++){
char c; c=getchar();
if(c=='b') a[i]=;
}
}
int main(){
init();
solve();
return ;
}
D(最短路+宽搜)
描述:一个迷宫,每个点可以通向四个方向中的一部分,只有两两相通的点才能走,也可以花费时间把所有点通向的方向顺时针旋转90度.求起点到终点花费的最短时间.
分析:一共就4张图,分别预处理出来.在一个点,要么就在原来的图上继续跑,要么走到顺时针旋转90度之后的图上去.(不看题解的我TLE).
#include <bits/stdc++.h>
using namespace std; const int maxn=+; int n,m,ans,xs,ys,xt,yt,cnt;
int head[maxn*maxn*];
bool vis[maxn*maxn*];
bool t[maxn][maxn][];
struct edge{
int to,next;
edge(int to=,int next=):to(to),next(next){}
}g[maxn*maxn**];
struct node{
int x,step;
node(int x=,int step=):x(x),step(step){}
};
inline int idx(int x,int y,int z){ return z*n*m+(x-)*m+y; }
bool tag(int id){
for(int i=;i<;i++)
if(idx(xt,yt,i)==id) return true;
return false;
}
void add_edge(int u,int v){
g[++cnt]=edge(v,head[u]); head[u]=cnt;
g[++cnt]=edge(u,head[v]); head[v]=cnt;
}
void add_edge2(int u,int v){
g[++cnt]=edge(v,head[u]); head[u]=cnt;
}
void bfs(){
queue <node> q;
q.push(node(idx(xs,ys,),));
while(!q.empty()){
node t=q.front(); q.pop();
int x=t.x,step=t.step;
if(tag(x)){
ans=step;
return;
}
for(int i=head[x];i;i=g[i].next){
int y=g[i].to;
if(vis[y]) continue;
vis[y]=true;
q.push(node(y,step+));
}
}
}
void init(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
char c; while(c=getchar(), c=='\n');
if(c=='+') t[i][j][]=t[i][j][]=t[i][j][]=t[i][j][]=true;
else if(c=='-') t[i][j][]=t[i][j][]=true;
else if(c=='|') t[i][j][]=t[i][j][]=true;
else if(c=='^') t[i][j][]=true;
else if(c=='>') t[i][j][]=true;
else if(c=='v') t[i][j][]=true;
else if(c=='<') t[i][j][]=true;
else if(c=='U') t[i][j][]=t[i][j][]=t[i][j][]=true;
else if(c=='R') t[i][j][]=t[i][j][]=t[i][j][]=true;
else if(c=='D') t[i][j][]=t[i][j][]=t[i][j][]=true;
else if(c=='L') t[i][j][]=t[i][j][]=t[i][j][]=true;
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
int x,y;
x=i; y=j+;//R
if(x<=n&&y<=m){
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
}
x=i+; y=j;//D
if(x<=n&&y<=m){
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
if(t[i][j][]&&t[x][y][]) add_edge(idx(i,j,),idx(x,y,));
}
for(int k=;k<;k++) add_edge2(idx(i,j,k),idx(i,j,(k+)%));
}
scanf("%d%d%d%d",&xs,&ys,&xt,&yt);
ans=-;
}
int main(){
init();
bfs();
printf("%d\n",ans);
return ;
}
E
并没有看...
CodeForces_#354_Div.2_2016.5.25(A+B+C)的更多相关文章
- CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子
CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...
- C#开发微信门户及应用(25)-微信企业号的客户端管理功能
我们知道,微信公众号和企业号都提供了一个官方的Web后台,方便我们对微信账号的配置,以及相关数据的管理功能,对于微信企业号来说,有通讯录中的组织架构管理.标签管理.人员管理.以及消息的发送等功能,其中 ...
- 25 highest paying companies: Which tech co outranks Google, Facebook and Microsoft?
Tech companies dominate Glassdoor’s ranking of the highest paying companies in the U.S., snagging 20 ...
- iOS 25个性能优化/内存优化常用方法
1. 用ARC管理内存 ARC(Automatic ReferenceCounting, 自动引用计数)和iOS5一起发布,它避免了最常见的也就是经常是由于我们忘记释放内存所造成的内存泄露.它自动为你 ...
- gnu coreutils-8.25 for win32 static - Beta
gnu.win32-coreutils-8.25.7z 2.7 Mb bc-1.06.tar.gz coreutils-8.25.tar.xz diffutils-3.5.tar.xz gawk-4. ...
- 25个 Git 进阶技巧
[ 原文] http://www.open-open.com/lib/view/open1431331496857.html 我已经使用git差不多18个月了,觉得自己对它应该已经非常了解.然后来自G ...
- 德国W家HIPP 奶粉有货播报:2014.6.25 HIPP 1+ 4盒装有货啦!
德国W家HIPP 奶粉有货播报:2014.6.25 HIPP 1+ 4盒装有货啦!
- [.net 面向对象程序设计进阶] (25) 团队开发利器(四)分布式版本控制系统Git——使用GitStack+TortoiseGit 图形界面搭建Git环境
[.net 面向对象程序设计进阶] (25) 团队开发利器(四)分布式版本控制系统Git——使用GitStack+TortoiseGit 图形界面搭建Git环境 本篇导读: 前面介绍了两款代码管理工具 ...
- 1Z0-053 争议题目解析25
1Z0-053 争议题目解析25 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 25.You enabled Flashback Data Archive on the INVEN ...
随机推荐
- C++ 二维数组(双重指针作为函数参数)
本文的学习内容参考:http://blog.csdn.net/yunyun1886358/article/details/5659851 http://blog.csdn.net/xudongdong ...
- Hyper-V 测试
云平台的虚拟服务器,基本上没有免费的(试用时间基本上都是1个月),按月收费最低的套餐(1个CPU核心.512内存)一般都是将近100元 所以索性还是自己搭建一个技术测试环境吧 上学的时候一直用的是VM ...
- 生产者消费者问题c语言实现
#include <stdio.h> #include <process.h> #include <Windows.h> //信号量与关键段 CRITICAL_SE ...
- 利用javascript Location访问Url,重定向,刷新页面
网上转来了, 方便以后查询参考 本文介绍怎么使用javascript Location对象读和修改Url.怎么重载或刷新页面.javascript提供了许多方法访问,修改当前用户在浏览器中访问的url ...
- VB6-图像分割利器 Microsoft Picture Clip控件
在医院做图像处理时碰到双面扫描仪,需要将扫描到的2张图像分割为一张并打印.在分割图像的过程中总是不得法,后来虽然有CBM666的指导,但给的方法也还是不太方便.无意中在翻一本vb书的时候看到了一个使用 ...
- LINQ实战
转载:http://www.cnblogs.com/yubinfeng/p/4567064.html 原作者:尼古拉斯~yu 文章部分内容在原文的基础上有删改. 我相信在net进阶的这个阶段,很 ...
- 【JPA】表达条件查询的关键字
1.通过解析方法名创建查询 框架在进行方法名解析时,会先把方法名多余的前缀截取掉,比如 find.findBy.read.readBy.get.getBy,然后对剩下部分进行解析.并且如果方法的最后一 ...
- Python从list删除元素
Paul同学刚来几天又要转走了,那么我们怎么把Paul 从现有的list中删除呢? 如果Paul同学排在最后一个,我们可以用list的pop()方法删除: >>> L = ['Ada ...
- C#基础|初探反射
什么是反射 我们编写的C#代码都可以编译成exe文件或dll文件.暂时先把他们叫做程序集吧,程序集中包含了很多信息.你写了一个类,类中会有字段,有属性,有方法,编译是会把这些信息保存在程序集中,暂时把 ...
- jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据(转)
jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据 问题:在serverfilter request获取不到post提交的 ...