Codeforces Beta Round #31 (Div. 2, Codeforces format)
Codeforces Beta Round #31 (Div. 2, Codeforces format)
http://codeforces.com/contest/31
A
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define maxn 1000005
- typedef long long ll;
- typedef unsigned long long ull;
- /*#ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif */
- int a[];
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- cin>>n;
- for(int i=;i<=n;i++) cin>>a[i];
- for(int i=;i<=n;i++){
- for(int j=;j<=n;j++){
- for(int k=;k<=n;k++){
- if(i!=j&&j!=k){
- if(a[i]==a[j]+a[k]){
- cout<<i<<" "<<j<<" "<<k<<endl;
- return ;
- }
- }
- }
- }
- }
- cout<<-<<endl;
- }
B
模拟
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define maxn 1000005
- typedef long long ll;
- typedef unsigned long long ull;
- /*#ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif */
- int a[];
- int Check(string str){
- int pre=-;
- int pos=-;
- for(int i=;i<str.length();i++){
- if(str[i]=='@'){
- pos=i;
- if(pre<i-&&i+<str.length()){
- pre=i+;
- }
- else{
- return -;
- }
- }
- }
- return pos;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("1.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- string str;
- cin>>str;
- int pos=Check(str);
- if(pos!=-){
- for(int i=;i<str.length();i++){
- cout<<str[i];
- if(str[i]=='@'){
- if(pos!=i){
- cout<<str[i+];
- i++;
- if(i<str.length()-){
- cout<<',';
- }
- }
- }
- }
- }
- else cout<<"No solution"<<endl;
- }
C
暴力
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define maxn 1000005
- typedef long long ll;
- typedef unsigned long long ull;
- /*#ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif */
- struct sair{
- int s,e,pos;
- }a[];
- bool cmp(sair a,sair b){
- if(a.s==b.s) return a.e<b.e;
- return a.s<b.s;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("1.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- cin>>n;
- for(int i=;i<n;i++){
- cin>>a[i].s>>a[i].e;
- a[i].pos=i+;
- }
- sort(a,a+n,cmp);
- vector<int>ans;
- int flag;
- for(int i=;i<n;i++){
- int pre=-;
- flag=;
- for(int j=;j<n;j++){
- if(i!=j){
- if(pre==-){
- pre=a[j].e;
- }
- else{
- if(pre>a[j].s){
- flag=;
- }
- else{
- pre=a[j].e;
- }
- }
- }
- }
- if(!flag){
- ans.pb(a[i].pos);
- }
- }
- cout<<ans.size()<<endl;
- sort(ans.begin(),ans.end());
- for(int i=;i<ans.size();i++){
- cout<<ans[i]<<" ";
- }
- }
D
bfs求连通块,模拟剪纸的过程
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define maxn 1000005
- typedef long long ll;
- typedef unsigned long long ull;
- /*#ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif */
- int n,m,k;
- int book[][];
- int dir[][]={,,,,,-,-,};
- int bfs(int x,int y){
- queue<pair<int,int> >Q;
- int ans=;
- book[x][y]=;
- Q.push(make_pair(x,y));
- pair<int,int>p;
- while(!Q.empty()){
- p=Q.front();
- Q.pop();
- for(int i=;i<;i++){
- int xx=p.first+dir[i][];
- int yy=p.second+dir[i][];
- if(xx>=&&xx<=*n&&yy>=&&yy<=*m&&!book[xx][yy]){
- book[xx][yy]=;
- if((xx%)&&(yy%)){
- ans++;
- }
- Q.push(make_pair(xx,yy));
- }
- }
- }
- return ans;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- cin>>n>>m>>k;
- int a,b,c,d;
- while(k--){
- cin>>a>>b>>c>>d;///边为偶数
- a*=,b*=,c*=,d*=;
- if(a==c){
- if(b>d) swap(b,d);
- for(int i=b;i<=d;i++){
- book[a][i]=;
- }
- }
- else{
- if(a>c) swap(a,c);
- for(int i=a;i<=c;i++){
- book[i][b]=;
- }
- }
- }
- vector<int>ans;
- for(int i=;i<=*n;i++){
- for(int j=;j<=*m;j++){
- if(!book[i][j]&&(i%)&&(j%)){
- ans.pb(bfs(i,j));
- }
- }
- }
- sort(ans.begin(),ans.end());
- for(int i=;i<ans.size();i++){
- cout<<ans[i]<<" ";
- }
- cout<<endl;
- }
E
题意:给2*n个数字,A和B各选n个各组成一个数,使得A+B的和最大
DP,细节在代码里
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define maxn 1000005
- typedef long long ll;
- typedef unsigned long long ull;
- /*#ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- #endif */
- ll dp[][];
- ll p[];
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("1.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- string str;
- cin>>n;
- cin>>str;
- int len=*n;
- p[]=;
- for(int i=;i<=;i++){
- p[i]=p[i-]*;
- }
- ///dp[i][j] 表示A选了i个,B选了j个,dp[i][j]记录的是A+B的和
- for(int i=;i<=n;i++){
- for(int j=;j<=n;j++){
- ll tmp=str[*n-i-j]-'';///从后向前推
- if(i){
- dp[i][j]=dp[i-][j]+tmp*p[i-];
- }
- if(j){
- dp[i][j]=max(dp[i][j],dp[i][j-]+tmp*p[j-]);
- }
- cout<<dp[i][j]<<endl;
- }
- }
- int i=n,j=n;
- while(i||j){
- ll tmp=str[*n-i-j]-'';
- if(i>&&(tmp*p[i-]+dp[i-][j]==dp[i][j])){
- cout<<'H';
- i--;
- }
- else{
- cout<<'M';
- j--;
- }
- }
- cout<<endl;
- }
Codeforces Beta Round #31 (Div. 2, Codeforces format)的更多相关文章
- Codeforces Beta Round #32 (Div. 2, Codeforces format)
Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format)
Codeforces Beta Round #29 (Div. 2, Codeforces format) http://codeforces.com/contest/29 A #include< ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序
C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 拓扑排序
C. Mail Stamps One day Bob got a letter in an envelope. Bob knows that when Berland's post offic ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- setTimeout闭包常见问题
经常会遇到这样的问题,setTimeout按序输出循环数字,而不是最后输出同一个数字: 题目: for (var i = 0; i < 5; i++) { setTimeout(function ...
- js模板引擎初级
模板引擎:模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的html文档. 模板引擎的实现方式有 ...
- Windows常用命令实例
熟练使用DOS常用命令有助于提高工作效率. 1.windows+R:打开运行程序窗口 2.cmd:调用DOS命令窗口 3.mstsc:调用远程桌面命令窗口.mstsc -v 192.168..0.1 ...
- 21 week4 submit buidAndRun() node-rest-client
. 我们想实现一个提交代码的功能 这个功能有nodeserver 传到后边的server 验证 在返回给nodeserver 我们稍微修改一下ui ATOM修改文件权限不够 用下面命令 我们 Cont ...
- Hibernate学习笔记1.1(简单插入数据)
Hibernate是把以前的jdbc连接数据库的操作进行了一系列友好的封装,最好只用调用save即可,即将sql语句的这部分操作转化为面向对象的 Hibernate资源准备: 文档目录结构: 1.网址 ...
- ArcMap导入图层出现General function failure问题 [转]
ArcMap导入图层出现General function failure问题 [转] Link: http://www.cnblogs.com/angelx/p/3391967.html 问题描述 ...
- IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化:
IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化: IT蓝豹 ------------------> sqlite数据库版本升级 1.sqlite升级步骤: 1.自己写一个类继承自 ...
- mysql 数据库必备命令操作,入门练习一下
mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...
- table 合并内容相同的第一列
function mergeCells() { var tbodyTlth = $("#datatable_ajax1 tbody").find("tr").l ...
- webstocket 聊天
/** * 初始化socket **/ function initSocket(index_host){//端口号 if( !window.WebSocket ){ console.log(" ...