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 ...
随机推荐
- 安装ipython notebook
从http://cs231n.github.io/assignments2016/assignment1/开始说起,因为要学习cs231n课程,需要安装ipython notebook,原本电脑中安装 ...
- 九度OJ 1510 替换空格
题目地址:http://ac.jobdu.com/problem.php?pid=1510 题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We ...
- Windows Linux HackMacintosh
我想把Windows Linux HackMacintosh三类系统融入到一台笔记本上的神经病应该不多. 我的电脑就一个SATA硬盘,BIOS还不是EFI的.一共同时安装了Windows 8.1.Op ...
- .net Remoting 的工作原理是什么?
webservice和.net remoting都是用来通信的框架,它们最大的优点是可以像调用本地对象一样调用远程对象 区别:1.webservice是用的应用层协议http封装的,所以它可以被很多其 ...
- js:合同-已知起始日期、年限,自动计算截止日期
dateAddYear('2016-01-01', '3') ;//返回:2018-12-31 浏览器:ie11,ff 46.0.1(成功)360v8.1(急速模式,成功) 浏览器:360v8.1(兼 ...
- PERL代码摘录
1. 语法与数据结构 #嵌套哈希的赋值和取值 $HashTable{$key} = [@Array] #这个是赋值 @Array = @{ $HashTable{$key} } # 这个是取值 #Pe ...
- (转载)Delphi TStringList的用法
Delphi TStringList的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. TStringList 常用方法与属性: var List: TStringL ...
- Linux下实现流水灯等功能的LED驱动代码及测试实例
驱动代码: #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> ...
- Custome Buble Data Point
<navigation:Page xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/to ...
- windows8.1专业中文版一个可用的密钥分享
分享一个windows8.1专业中文版一个可用的密钥,亲测可用,联网输入密钥激活即可. PKHMN-TWQ6R-XDTH7-P4WW4-YR9T7