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> ...
随机推荐
- LeetCode 283 Move Zeroes(移动全部的零元素)
翻译 给定一个数字数组.写一个方法将全部的"0"移动到数组尾部.同一时候保持其余非零元素的相对位置不变. 比如,给定nums = [0, 1, 0, 3, 12],在调用你的函数之 ...
- REST技术第四步 多个參数注解问题
经过实验,发如今使用@BeanParam注解的查询类字段上. @FormParam和@QueryParam不能同一时候加上去,仅仅能加一个,否则会出现取不到数据的情况. 并且在方法參数上两个注解也不能 ...
- SDUT 3503 有两个正整数,求N!的K进制的位数
有两个正整数,求N!的K进制的位数 题目链接:action=showproblem&problemid=3503">http://sdutacm.org/sdutoj/prob ...
- 《modern operating system》 chapter 6 DEADLOCKS 笔记
DEADLOCKS Both processes are blocked and will remain so forever. This situation is called a deadlock ...
- 【bzoj1015】【JSOI2008】【星球大战】【并查集+离线】
Description 非常久曾经.在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器.并攻下了星系中差点儿全部的星球.这些星球 ...
- IO获取指定目录及其目录下子目录
一.需求:获取指定目录下,指定扩展名的文件(包含子目录中的) 二.需要用到的方法 1.FilenameFilter :返回抽象路径名的定义中表示此抽象路径名的目录中的文件的数组. filter.ac ...
- windows下使用mingw和msys编译GOTOBLAS和OpenBLAS
在windows下利用msys编译openBLAS若遇到错误提示: gcc: CreateProcess : No such file or directory 问题原因参考:http://www.c ...
- ora-12541无监听的一种场景
项目上突然出现无法连接Oracle数据库的情况,提示无监听程序. 现象: 查看 listener.ora配置无问题,用Net Configuration Assistant重建监听,NCA也处于假死状 ...
- Django的缓存,序列化,ORM操作的性能
1,缓存:把数据先保存在某个地方,下次再读取的时候不用再去原位置读取
- Deep Learning 28:读论文“Multi Column Deep Neural Network for Traffic Sign Classification”-------MCDNN 简单理解
读这篇论文“ Multi Column Deep Neural Network for Traffic Sign Classification”是为了更加理解,论文“Multi-column Deep ...