Codeforces Round #249 (Div. 2)
A。水题。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
using namespace std;
];
int main()
{
int n,m;
cin>>n>>m;
; i<=n; ++i) cin>>a[i];
;
;
; i<=n; ++i)
{
if(p<a[i])
{
p=m;
ans++;
}
p-=a[i];
}
cout<<ans<<endl;
;
}
B。用字符串读入数字。对于这个数字,从左往右看,寻找交换k次之内可得的最大数字,并交换到最左边。k再减去交换步数。如此直到k为0或者该数字达它可取的最大值。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
using namespace std;
string num;
int k;
int main()
{
cin>>num>>k;
) cout<<num<<endl;
else
{
string t=num;
sort(t.begin(),t.end(),greater<int>());
;
int len=num.size();
while(k)
{
if(num==t) break;
int maxp=st;
; i<min(st+k+,len); ++i)
if(num[i]>num[maxp]) maxp=i;
for(int i=maxp; i>st; --i)
{
swap(num[i],num[i-]);
k--;
}
st++;
}
cout<<num<<endl;
}
;
}
C。根据计算出的数字对,画一个图。
首先计算出所有的数字对,由于有负数,为了方便可以用map<int,int>来存图。取得点可能的上下左右边界值,再遍历该空间,画图即可。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> Pair;
map<Pair,int > vis;
];
int main()
{
int n;
cin>>n;
; i<=n; ++i) cin>>a[i];
,left=,down=,right=;
,y=;
vis[Pair(x,y)]=;
; i<=n; ++i)
{
; j<=a[i]; ++j)
{
x++;
) y++;
else y--;
)
vis[Pair(x,y)]=;
else
vis[Pair(x,y+)]=-;
}
up=max(up,y);
down=min(down,y);
left=min(left,x);
right=max(right,x);
}
for(int i=up; i>down; --i)
{
; j<=right; ++j)
{
int &u=vis[Pair(j,i)];
) cout<<"/";
) cout<<"\\";
else cout<<" ";
}
cout<<endl;
}
;
}
D。预处理+统计。
统计三角形个数。要求选定的三角形的边上不含有黑点。
明显这样图中的三角形只能是等腰直角三角形。我们可以预处理出两条对角线上的白点个数。然后枚举一个点,再递增边长,在保证两条等边不含黑点的前提下,通过判断第三条边上的白点个数来判断第三条边上是否含有黑点。
这样的三角形一共有八种。第一类是斜边在对角线上的三角形,可以枚举直角点,再递增边,判断斜边。第二类是斜边在行或列上的三角形,这样可以枚举斜边中点,沿中点递增边,然后判断两条直角边。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
][];
][];
][],UR[][];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
; i<=n; ++i)
{
scanf();
; j<=m; ++j)
mp[i][j]=(grid[i][j]==:;
}
; i<=n; ++i)
; j<=m; ++j)
UL[i][j]=UL[i-][j-]+mp[i][j];
; i<=n; ++i)
; --j)
UR[i][j]=UR[i-][j+]+mp[i][j];
;
; i<=n; ++i)
; j<=m; ++j)
if(mp[i][j])
{
; mp[i-d][j]&&mp[i][j-d]; ++d) //左上
][j+]==d+)
ans++;
; mp[i+d][j]&&mp[i][j+d]; ++d)//右下
][j+d+]==d+)
ans++;
; mp[i-d][j]&&mp[i][j+d]; ++d)//右上
][j-]==d+)
ans++;
; mp[i+d][j]&&mp[i][j-d]; ++d)//左下
][j-d-]==d+)
ans++;
; mp[i-d][j]&&mp[i+d][j]; ++d) //左
][j+]==d+&&UL[i+d][j]-UL[i-][j-d-]==d+)
ans++;
; mp[i+d][j]&&mp[i-d][j]; ++d)//右
][j-]==d+&&UR[i+d][j]-UR[i-][j+d+]==d+)
ans++;
; mp[i][j-d]&&mp[i][j+d]; ++d) //上
][j+]==d+&&UL[i][j+d]-UL[i-d-][j-]==d+)
ans++;
; mp[i][j+d]&&mp[i][j-d]; ++d)//下
][j+d+]==d+&&UL[i+d][j]-UL[i-][j-d-]==d+)
ans++;
}
printf("%d\n",ans);
;
}
E。找规律+构造。
答案大致有这么几种情况:
第一类:
1212
3434
1212
3434
或者
1232
3414
1232
1414等等
这类的特点是以左上角的四个格为单元,不断在每列上重复得到。而在每行上,可分为第一、二行交不交换几种情况。
第二类:
1212
3434
2121
3434
或者
1212
3434
2121
4343等等
这类的特点是以左上角的四个格为单元,不断在每行上重复得到。而在每列上,可分为第一、二列交不交换几种情况。
我们需要找出所有情况判断是否和给出的矩阵匹配即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
][];
int n,m;
][];
bool judge(int x,int y)
{
'!=arr[x][y]) return false;
return true;
}
void output()
{
; i<=n; ++i)
{
; j<=m; ++j)
printf("%d",arr[i][j]);
printf("\n");
}
}
bool check1()
{
; j<=; ++j)
; i<=n; ++i)
{
arr[i][j]=arr[i-][j];
if(!judge(i,j))
return false;
}
; j<=m; ++j)
{
bool ok=true;
arr[][j]=arr[][j-];
arr[][j]=arr[][j-];
,j)||!judge(,j)) ok=false;
; i<=n&&ok; ++i)
{
arr[i][j]=arr[i-][j];
if(!judge(i,j)) ok=false;
}
if(ok) continue;
ok=true;
arr[][j]=arr[][j-];
arr[][j]=arr[][j-];
,j)||!judge(,j)) ok=false;
; i<=n&&ok; ++i)
{
arr[i][j]=arr[i-][j];
if(!judge(i,j))
ok=false;
}
if(!ok) return false;
}
return true;
}
bool check2()
{
; i<=; ++i)
; j<=m; ++j)
{
arr[i][j]=arr[i][j-];
if(!judge(i,j))
return false;
}
; i<=n; ++i)
{
bool ok=true;
arr[i][]=arr[i-][];
arr[i][]=arr[i-][];
)||!judge(i,)) ok=false;
; j<=m&&ok; ++j)
{
arr[i][j]=arr[i][j-];
if(!judge(i,j))
ok=false;
}
if(ok) continue;
arr[i][]=arr[i-][];
arr[i][]=arr[i-][];
ok=true;
)||!judge(i,)) ok=false;
; j<=m&&ok; ++j)
{
arr[i][j]=arr[i][j-];
if(!judge(i,j))
ok=false;
}
if(!ok) return false;
}
return true;
}
int main()
{
scanf("%d%d",&n,&m);
; i<=n; ++i)
scanf();
]= {,,,};
do
{
arr[][]=p[];
arr[][]=p[];
arr[][]=p[];
arr[][]=p[];
bool ok=true;
; i<=&&ok; ++i)
; j<=&&ok; ++j)
if(!judge(i,j))ok=false;
if(!ok) continue;
if(check1()||check2())
{
output();
;
}
}
));
puts(");
;
}
Codeforces Round #249 (Div. 2)的更多相关文章
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!
http://codeforces.com/contest/435/problem/C
- Codeforces Round #249 (Div. 2)B(贪心法)
B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #249 (Div. 2) A题
链接:http://codeforces.com/contest/435/problem/A A. Queue on Bus Stop time limit per test 1 second m ...
- Codeforces Round #249 (Div. 2) D. Special Grid 枚举
题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...
- Codeforces Round #249 (Div. 2) 总结
D.E还是很难的.....C不想多说什么... A:提意:给出每一组人的个数,以及一次车载容量,求出最少需要多少次才能载走所有的人. water: http://codeforces.com/cont ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #249 (Div. 2) C. Cardiogram
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #249 (Div. 2) A. Black Square
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素, 如果第i个元素比第i-1个元素小,则不交换 如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元 ...
随机推荐
- iOS 国际化多语言设置 xcode7
iOS 国际化多语言设置 方式一: 1. 在storyboard中创建好UI,然后在 project 里面 Localizables 栏目里面,添加你需要的语言:默认是Englist; 比如这里我添 ...
- [redis] 分布式 Redis 的 CRUD 实现
1.applicationContext-redis.xml <?xml version="1.0" encoding="UTF-8"?> < ...
- ubuntu安装SCrapy
依次安装 sudo apt-get install build-essential; sudo apt-get install python-dev; sudo apt-get install lib ...
- HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game ...
- maven install 时提示“程序包 javax.crypto不存在”
但是javax.crypto是在jdk的jre\lib目录下的 解决方案: <compilerArguments> <bootclasspath>${java.home}/li ...
- 《JavaScript权威指南》读书笔记(三)
日期:2015-12-05 浏览器location和history: replace不会显示历史,location会: history对象脚本不能真正访问,但支持三种方法:back().foward( ...
- poj2284 That Nice Euler Circuit(欧拉公式)
题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...
- Wilcoxon test
clear load NPSVOR name={'SCV1V1','SVC1VA','SVR','CSSVC','SVMOP','NNOP','ELMOP','POM',... 'NNPOM', 'S ...
- C#多态问题
为什么对这个感觉趣呢.因为以前写过两篇关于这个多态和重载混合起来很乱的调用情况分析,自从哪以后,我自认为随便乱写一些继承多态的代码都应该难不到我.但是今天看到一段代码有一个地方计算错误了,所以有必要写 ...
- LevelDb简单介绍和原理——本质:类似nedb,插入数据文件不断增长(快照),再通过删除老数据做更新
转自:http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html 有时间再好好看下整个文章! 说起LevelDb也许您不清楚,但是如果作 ...