Codeforces Beta Round #96 (Div. 2) (A-E)
写份DIV2的完整题解
A
判断下HQ9有没有出现过
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 112
- #define LL long long
- #define INF 0xfffffff
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- char s[N];
- int main()
- {
- int i,j,k;
- cin>>s;
- k = strlen(s);
- for(i = ; i < k ;i++)
- if(s[i]=='H'||s[i]==''||s[i]=='Q')
- break;
- if(i==k)
- puts("NO");
- else
- puts("YES");
- return ;
- }
B
模拟下就OK
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 112
- #define LL long long
- #define INF 0xfffffff
- #define mod 1000003
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- char s[N];
- int a[];
- int main()
- {
- int i,j,k;
- a['>'] = ;
- a['<'] = ;
- a['+'] = ;
- a['-'] = ;
- a['.'] = ;
- a[','] = ;
- a['['] = ;
- a[']'] = ;
- cin>>s;
- k = strlen(s);
- int ans = ;
- for(i = ;i < k ; i++)
- {
- // cout<<a[s[i]]<<endl;
- ans = (ans*+a[s[i]])%mod;
- }
- cout<<ans<<endl;
- return ;
- }
C
题意有点费解 给定操作 使其数字变为字符 先给你字符 问原先数字为多少 模拟。。
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 112
- #define LL long long
- #define INF 0xfffffff
- #define mod 256
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- char s[N];
- int a[];
- int main()
- {
- int i,j,k;
- gets(s);
- k = strlen(s);
- int ans = ;
- int kt = ;
- for(i = ;i < k ; i++)
- {
- int x = s[i];
- int y = kt;
- int g = ;kt=;
- memset(a,,sizeof(a));
- while(y)
- {
- a[g++] = y%;
- y/=;
- }
- for(j = ; j < ;j++)
- kt+=pow(,-j-)*a[j];
- memset(a,,sizeof(a));
- g = ;
- while(x)
- {
- a[g++] = x%;
- x/=;
- }
- int ans = ;
- for(j = ; j < ;j++)
- ans+=pow(,-j-)*a[j];
- kt = (kt-ans+mod)%mod;
- cout<<kt<<endl;
- kt = s[i];
- }
- return ;
- }
D
题意更是费解 大意:你当前在某一个颜色块中 你有两个指向标 一个是向另一块前进的方向 另一个是在本块的前进方向 0块和边外不能走 问m次后你在哪个块中
模拟。。
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 112
- #define LL long long
- #define INF 0xfffffff
- #define mod 256
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- char s[][];
- int a[][][],n,k;
- int judge(int x,int y)
- {
- if(x<||x>=n||y<||y>=k)
- return ;
- if(s[x][y]=='') return ;
- return ;
- }
- int main()
- {
- int i,j,m,g;
- cin>>n>>m;
- for(i = ; i < n ;i++)
- cin>>s[i];
- k = strlen(s[]);
- for(i = ;i < n ;i++)
- {
- for(j = ; j < k ;j++)
- {
- for(g = j ; g >= ; g--)
- if(s[i][g]!=s[i][j]) break;
- a[i][j][] = g+;
- for(g = i ; g >= ; g--)
- if(s[g][j]!=s[i][j]) break;
- a[i][j][] = g+;
- for(g = j ; g < k; g++)
- if(s[i][g]!=s[i][j]) break;
- a[i][j][] = g-;
- for(g = i ; g < n ;g++)
- if(s[g][j]!=s[i][j]) break;
- a[i][j][] = g-;
- }
- }
- int d1 = ,d2 = ,x = ,y = ;
- char c = s[][];
- int k1 = ;
- while(k1<=m)
- {
- if(d1==||d1==)
- x = a[x][y][d1];
- else y = a[x][y][d1];
- if(d2==||d2==)
- x = a[x][y][d2];
- else y = a[x][y][d2];
- int tx,ty;
- if(d1==)
- {
- tx = x-;ty = y;
- }
- else if(d1==)
- {
- tx = x;ty = y+;
- }
- else if(d1==)
- {
- tx = x+;ty = y;
- }
- else
- {
- tx = x;ty = y-;
- }
- if(!judge(tx,ty))
- {
- //cout<<",";
- if((d2+)%==d1)
- d2 = (d1+)%;
- else
- {
- d1 = (d1+)%;d2 = (d1-+)%;
- }
- }
- else
- {
- c = s[tx][ty];
- x = tx,y = ty;
- }
- k1++;
- //x = tx
- //cout<<c<<" "<<d1<<" "<<d2<<" "<<k1<<" "<<x<<" "<<y<<endl;
- }
- cout<<c<<endl;
- return ;
- }
E
当时的思路貌似不太对 按照zp说的思路又重写了一遍
dp[i][j][0] 表示在i位置已经改变了j次方向为正的最大移动距离 dp[i][j][1]类似表反方向。
- #include <iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<stdlib.h>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<set>
- using namespace std;
- #define N 112
- #define LL long long
- #define INF 0xfffffff
- #define mod 256
- const double eps = 1e-;
- const double pi = acos(-1.0);
- const double inf = ~0u>>;
- int dp[N][][];
- char s[N];
- int main()
- {
- int i,j,k;
- cin>>s;
- cin>>k;
- int kk = strlen(s);
- for(i = ; i < kk ; i++)
- for(j = ; j <= k ; j++)
- dp[i][j][] = dp[i][j][] = -INF;
- if(s[]=='T')
- {
- for(i = ; i <= k ; i++)
- {
- if(i%!=)
- dp[][i][] = -;
- else
- dp[][i][] = ;
- }
- }
- else
- {
- for(i = ; i <= k ; i++)
- if(i%==)
- dp[][i][] = ;
- else
- dp[][i][] = ;
- }
- for(i = ; i < kk ;i++)
- {
- if(s[i]=='T')
- {
- dp[i][][] = dp[i-][][];
- dp[i][][] = dp[i-][][];
- }
- else
- {
- dp[i][][] = dp[i-][][]+;
- dp[i][][] = dp[i-][][]-;
- }
- for(j = ; j <= k ; j++)
- {
- if(s[i]=='T')
- {
- dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]+);
- dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]-);
- }
- else
- {
- dp[i][j][] = max(dp[i-][j][]+,dp[i-][j-][]);
- dp[i][j][] = max(dp[i-][j][]-,dp[i-][j-][]);
- }
- }
- }
- int ans1 = max(dp[kk-][k][],dp[kk-][k][]);
- for(i = ; i < kk ; i++)
- for(j = ; j <= k ; j++)
- dp[i][j][] = dp[i][j][] = -INF;
- if(s[]=='T')
- {
- for(i = ; i <= k ; i++)
- {
- if(i%!=)
- dp[][i][] = ;
- else
- dp[][i][] = ;
- }
- }
- else
- {
- for(i = ; i <= k ; i++)
- if(i%==)
- dp[][i][] = -;
- else
- dp[][i][] = ;
- }
- for(i = ; i < kk ;i++)
- {
- if(s[i]=='T')
- {
- dp[i][][] = dp[i-][][];
- dp[i][][] = dp[i-][][];
- }
- else
- {
- dp[i][][] = dp[i-][][]+;
- dp[i][][] = dp[i-][][]-;
- }
- for(j = ; j <= k ; j++)
- {
- if(s[i]=='T')
- {
- dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]+);
- dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]-);
- }
- else
- {
- dp[i][j][] = max(dp[i-][j][]+,dp[i-][j-][]);
- dp[i][j][] = max(dp[i-][j][]-,dp[i-][j-][]);
- }
- }
- }
- int ans2 = max(dp[kk-][k][],dp[kk-][k][]);
- //cout<<ans1<<" "<<ans2<<endl;
- int ans = max(ans1,ans2);
- cout<<ans<<endl;
- return ;
- }
Codeforces Beta Round #96 (Div. 2) (A-E)的更多相关文章
- Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP
题目链接:http://codeforces.com/contest/132/problem/C C. Logo Turtle time limit per test 2 seconds memory ...
- Codeforces Beta Round #96 (Div. 2) E. Logo Turtle dp
http://codeforces.com/contest/133/problem/E 题目就是给定一段序列,要求那个乌龟要走完整段序列,其中T就是掉头,F就是向前一步,然后开始在原点,起始方向随意, ...
- Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心
D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...
- Codeforces Beta Round #96 (Div. 1) C. Logo Turtle DP
C. Logo Turtle A lot of people associate Logo programming language with turtle graphics. In this c ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #69 (Div. 2 Only)
Codeforces Beta Round #69 (Div. 2 Only) http://codeforces.com/contest/80 A #include<bits/stdc++.h ...
- Codeforces Beta Round #40 (Div. 2)
Codeforces Beta Round #40 (Div. 2) http://codeforces.com/contest/41 A #include<bits/stdc++.h> ...
随机推荐
- gbk转utf-8 iconv 编码转换
linux以下有时候 字符须要进行编码转换(爬虫将gbk转为utf-8编码...).一般能够选择iconv函数. 终端以下 输入 man 3 iconv 得到 iconv函数的用法. 个人看习惯了 ...
- OTG识别原理
如图1所示,那个是Micro USB的母头,可以清晰看到有5pin,分别是(不分顺序):Vbus.GND.D+.D-.ID.当移动设备,类似手机.平板电脑等要支持OTG功能,就必须使用这个接口,而且电 ...
- Qt实现一个简单的TextEditor
使用QT实现简单的TextEditor: 首先在窗口添加部件TextEditor,并设置中文字符 MainWindow::MainWindow(QWidget *parent) : QMainWind ...
- udhcp源码详解(三)上 之配置信息的读取
上节介绍了存储管理配置信息的结构体struct server_config_t,该结构体贯穿整个server端程序的运行. 在dhcpd.c里的用该结构体定义个一个全局的变量: struct serv ...
- IIS+Asp.Net Mvc必须知道的事(解决启动/重启/自动回收站点后第一次访问慢问题)
问题现象: Asp.net Mvc站点部署在IIS上后,第一个用户第一次访问站点,都会比较慢,确切的说是访问站点的Action页面(即非静态页面,因为静态页面直接由IIS处理返回给用户即完成请求,而A ...
- 我的kindle书单
刚刚入手kindle,希望能够持续阅读,不断进步. 列下书单,记录我的阅读足迹,更希望园友若有好书多多推荐,互相交流. # keep updating ... 我的kindle书单 book name ...
- Android 4.4.2 动态加入JNI库方法记录 (二 app应用层)
欢迎转载,务必注明出处:http://blog.csdn.net/wang_shuai_ww/article/details/44458553 源代码下载地址:http://download.csdn ...
- Spring中AOP的使用
问题:什么是AOP? 答:AOP基本概念:Aspect-Oriented Programming,面向方面编程的简称,Aspect是一种新的模块化机制.用来描写叙述分散在对象.类或方法中的横切关注点( ...
- Bean Query 第一个版本号(1.0.0)已公布
BeanQuery 是一个把对象转换为Map的Java工具库. 支持选择Bean中的一些属性.对结果进行排序和依照条件查询. 不只能够作用于顶层对象,也能够作用于子对象.很多其它具体的介绍能够看我的博 ...
- asp.net项目与开源单点登录项目CAS的结合
这段时间搞的一个asp.net mvc项目,采用了单点登录. 这个单点登录就是CAS,一个开源的JAVA项目.当然,这并不影响ASP.NET项目结合它来进行登录.因为各自分工不同:单点登录(管它是不是 ...