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

  1. CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子

    CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...

  2. C#开发微信门户及应用(25)-微信企业号的客户端管理功能

    我们知道,微信公众号和企业号都提供了一个官方的Web后台,方便我们对微信账号的配置,以及相关数据的管理功能,对于微信企业号来说,有通讯录中的组织架构管理.标签管理.人员管理.以及消息的发送等功能,其中 ...

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

  4. iOS 25个性能优化/内存优化常用方法

    1. 用ARC管理内存 ARC(Automatic ReferenceCounting, 自动引用计数)和iOS5一起发布,它避免了最常见的也就是经常是由于我们忘记释放内存所造成的内存泄露.它自动为你 ...

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

  6. 25个 Git 进阶技巧

    [ 原文] http://www.open-open.com/lib/view/open1431331496857.html 我已经使用git差不多18个月了,觉得自己对它应该已经非常了解.然后来自G ...

  7. 德国W家HIPP 奶粉有货播报:2014.6.25 HIPP 1+ 4盒装有货啦!

    德国W家HIPP 奶粉有货播报:2014.6.25 HIPP 1+ 4盒装有货啦!

  8. [.net 面向对象程序设计进阶] (25) 团队开发利器(四)分布式版本控制系统Git——使用GitStack+TortoiseGit 图形界面搭建Git环境

    [.net 面向对象程序设计进阶] (25) 团队开发利器(四)分布式版本控制系统Git——使用GitStack+TortoiseGit 图形界面搭建Git环境 本篇导读: 前面介绍了两款代码管理工具 ...

  9. 1Z0-053 争议题目解析25

    1Z0-053 争议题目解析25 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 25.You enabled Flashback Data Archive on the INVEN ...

随机推荐

  1. 一种c#深拷贝方式完胜java深拷贝(实现上的对比)

    楼主是一名asp.net攻城狮,最近经常跑java组客串帮忙开发,所以最近对java的一些基础知识特别上心.却遇到需要将一个对象深拷贝出来做其他事情,而原对象保持原有状态的情况.(实在是不想自己new ...

  2. SQL 刪除

    SQL 刪除 1.delete from table_name 2.drop table table_name drop table is different from deleting all of ...

  3. OpenJudge / Poj 1928 The Peanuts C++

    链接地址:http://bailian.openjudge.cn/practice/1928 题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 Mr. Robinson and h ...

  4. [翻译][MVC 5 + EF 6] 9:异步和存储过程

    原文:Async and Stored Procedures with the Entity Framework in an ASP.NET MVC Application 1.为什么使用异步代码: ...

  5. ubuntu12.04 U盘自动挂载配置

    Ubuntu12.04禁止U盘等设备的自动挂载方法如下: 在图形界面(字符界面无效)内进入系统终端,ctrl+alt+T或者gnome-terminal 禁止自动挂载:$ gsettings seto ...

  6. (转)HTTP协议(2)

    转自:http://kb.cnblogs.com/page/130970/  作者 :小坦克 当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无 ...

  7. Extension method for type

    扩展其实真的很简单 msdn是这样规定扩展方法的:"扩展方法被定义为静态方法,但它们是通过实例方法语法进行调用的. 它们的第一个参数指定该方法作用于哪个类型,并且该参数以 this 修饰符为 ...

  8. 我写了个教程《一步步教你把ubuntu安装到U盘》

    一步步教你把ubuntu安装到U盘 作者 Val 2452013147@qq.com 原因: 由于某些原因(学生党),需要把ubuntu安装到U盘到处走,百度了一下,教程都不是很好,要么很复杂,要么不 ...

  9. Appdelegate 导航操作

    隐藏返回按钮 self.navigationItem.hidesBackButton = YES; 设置导航的透明度 self.navigationController.navigationBar.t ...

  10. C# - 接口,继承

    接口 接口是把公共实例(非静态)方法和属性组合起来,以封装特定功能的一个集合.不能像实例化一个类那样实例化接口.接口不能包含实现其成员的任何代码,而只能定义成员本身.实现过程必须在实现接口的类中完成. ...