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 ...
随机推荐
- 再也不要看到Eclipse万恶的arg0,arg1提示
不知道大家跟我是否一下,遇到arg的提示. @Override public void onDateChanged(DatePicker arg0, int arg1, int arg2, int a ...
- List分页显示
//对List集合 数据进行分页 int pageNum = page.getPageNo();// 当前显示第几页 int perPageNum = page.getPageSize(); // ...
- C bit 操作
C 位 操作 一.C bit 操作(C语言 二进制位 操作) 1.Setting a bit Use the bitwise OR operator (|) to set a bit. number ...
- OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT
1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...
- hdu 5014 Number Sequence
为了a异或b的和最大,只需另b在不大于n的情况下按位取反即可. 这里有两个输出小技巧可以参考: 1.在用printf输出__int64时,在windows下使用格式"%I64d", ...
- Eat that Frog
Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...
- C# 读取快捷方式指向的文件
C# 读取快捷方式指向的文件 [Flags()] public enum SLR_FLAGS { SLR_NO_UI = 0x1, SLR_ANY_MATCH = 0x2, SLR_UPDATE = ...
- 1. Window环境下 - 开发环境的配置: (安装Android Studio 2.1)
0. Java简介: 1990年Sun公司预料嵌入式系统将在未来家用电器领域大显生手, 于是成立了一个由James Gosling领导的"Green计划"(首席科学家Bill Jo ...
- 什么是UI控件
凡是带有Widget参数的组件都是控件.
- Catch Application Exceptions in a Windows Forms Application
You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. Thi ...