记codeforces两题
2016-03-19 20:44
453 查看
A。http://codeforces.com/contest/653/problem/A
错在for(int i=0; i<v.size()-2; i++) //当v.size()<2时,v.size()-2非负。
B。http://codeforces.com/contest/653/problem/B
状态不超过6^6次方种,暴力即可,
#stl很好用。
错在for(int i=0; i<v.size()-2; i++) //当v.size()<2时,v.size()-2非负。
#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include<stdlib.h> #include<iostream> using namespace std; int main(){ int n; while(scanf(" %d", &n)==1){ vector<int> v; bool have=false; for(int i=0; i<n; i++){ int t; scanf(" %d", &t); v.push_back(t); } // cout<<v.size()<<endl; sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); // cout<<v.size()<<endl; for(int i=0; i<v.size()-2; i++){ int t0=v[i], t1=v[i+1], t2=v[i+2]; if(abs(t0-t1)<3 && abs(t1-t2)<3 && abs(t2-t0)<3){ have=true; break; } } cout<<(have?"YES":"NO")<<endl; } return 0; }
B。http://codeforces.com/contest/653/problem/B
状态不超过6^6次方种,暴力即可,
#stl很好用。
#include<stdio.h> #include<string> #include<iostream> using namespace std; int n, q; string s[36]; int count(const string cur){ if(cur.size()==n) return 1; int cnt=0; for(int i=0; i<q; i++){ if(cur[0]!=s[i][3]) continue; string st(cur); st.replace(0, 1, s[i].substr(0,2)); cnt+=count(st); } return cnt; } int main(){ while(cin>>n>>q){ getchar(); for(int i=0; i<q; i++){ getline(cin, s[i]); // cout<<s[i]<<endl; } cout<<count("a")<<endl; } return 0; }
相关文章推荐
- Hibernate逍遥游记-第2章-使用hibernate.properties
- debian ubuntu linux系好用的包管理工具 aptitude
- 输入一个多项式F(X) 计算出(F(X))^P
- 简单谈谈C++中的引用与指针
- 关于surf显示立体图,可视化分析数据
- 初识NuGet - 概念, 安装和使用
- jdk环境变量配置
- Ajax and php 2.5
- Android四大组件之Service工作原理
- 转自一位学长的日志安排
- 学习进度条(三)
- 压缩感知的MP算法
- VTK环境搭建注意事项
- 软件测试作业(三)
- Java多线程编程
- android studio + bluestack
- Linux 文件传输 lrzsz,scp
- LeetCode-73-Set Matrix Zeroes(数组)-Medium
- PHP表单传值
- 打印*号