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个元 ...
随机推荐
- java 模板
模板模式: 解决某类事情的步骤有些是固定的,有些是会发生变化的,这时我们提供 一个模板代码,从而提高效率. 模板模式的作用: 1.解决这类事情其中一件的解决方案. 2.分析代码,把发生变化的代码抽象取 ...
- innodb_fast_shutdown中值为1或者2的区别是?
innodb_fast_shutdown=0 , 1 , 2时的意思分别是 0 把buffer pool中的脏页刷到磁盘和合并insert buffer,当然包括redo log也会写到磁盘中. 2 ...
- 应用 Middleware
主要应用场景:过滤HTTP请求 laravel本身自带了几个Middleware在app/http/middleware目录下面 然后在app/http/kernel.php中注册 自定义一个midd ...
- ajax正确的简单封装“姿势”
window.meng = window.meng || {}; (function ($) { function getAjaxDate(url, apikey) { var datas; $.aj ...
- hdu 3038 How Many Answers Are Wrong ( 带 权 并 查 集 )
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- Java DES 加解密文件
import com.mchange.v2.io.DirectoryDescentUtils; import javax.crypto.Cipher;import javax.crypto.Ciphe ...
- MySQL数据库百万级高并发网站实战
在一开始接触PHP接触MYSQL的时候就听不少人说:“MySQL就跑跑一天几十万IP的小站还可以,要是几百万IP就不行了”,原话不记得了,大体 就是这个意思.一直也没有好的机会去验证这个说法,一是从没 ...
- DataGridView复选框实现单选功能(二)
双击DataGridView进入事件 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventA ...
- c# 配置文件之configSections配置
对于小型项目来说,配置信息可以通过appSettings进行配置,而如果配置信息太多,appSettings显得有些乱,而且在开发人员调用时,也不够友好,节点名称很容易写错,这时,我们有几种解决方案 ...
- python处理url中的中文编码,以及其他编码问题
1.python中的urlencode与urldecode 2.各种编码转换在线工具 3.python用于url解码和中文解析的小脚本(python url decoder) 4.如何只对url中的中 ...