Codeforces Round #189 (Div. 2)
题目地址:http://codeforces.com/contest/320
第一题:基本题,判断mod 1000,mod 100.,mod 10是不是等于144、14、1,直到为0
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; const int N=10001;
typedef long long LL; int main()
{
int i,j,t,T,n;
int a[3]={144,14,1};
while(cin>>n)
{
int flag=0;
while(n)
{
if(n%1000==144)
n/=1000;
else if(n%100==14)
n/=100;
else if(n%10==1)
n/=10;
else{
flag=1;
break;
}
}
if(flag==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
第二题:给你一些单向路径。
"1 x y"-----插入
"2 a b"----判断
让你判断能否从a到b。
用深搜,开始的时候vis标记每次做完回溯都修改标记,结果超时了,最后有人说回溯的时候不需要修改,
自己想了想,好像是这样的,因为是单向的,到达一个点了之后不管后面怎样都还是可以到这个点。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef long long LL;
const int N=105; int parent[N]; int x[N],y[N];
int m,flag;
int a,b,c;
int vis[N]; void dfs(int t)
{
vis[t]=1;
if(flag==1)
return ;
if(t==c)
{
flag=1;
return ;
}
for(int i=1;i<=m;i++)
{
if(vis[i]==1)
continue;
if(x[t]>x[i]&&x[t]<y[i]||y[t]>x[i]&&y[t]<y[i])
{
dfs(i);//这个地方不能要 vis[i]=0; 要了就TLE
}
}
} int main()
{
int i,j,t,T,n,xx;
scanf("%d",&T);
m=0;
while(T--)
{ scanf("%d%d%d",&a,&b,&c);
if(a==1)
{
m++;
x[m]=b;
y[m]=c;
}
if(a==2)
{
flag=0;
memset(vis,0,sizeof(vis));
dfs(b);
if(flag==1)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
第三题:打表找规律。
从后往前走,
当遇见1的时候,last=(last*2+a4[j])%II; temp=last;
当遇见0的时候,last=(last*2)%II;
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;
typedef long long LL;
const int N=105;
const LL II=1000000007; char s[N];
LL a4[N]; int main()
{
int i,j,t,T,n,xx;
a4[0]=1;
for(i=1;i<N;i++)
{
a4[i]=(a4[i-1]*4)%II;
//printf("%lld\n",a4[i]);
}
scanf("%s",s);
int len=strlen(s);
int k=0;
while(k<len&&s[k]=='0')
k++;
if(k==len)
{
printf("0\n");
return 0;
}
LL last=0,temp=0;
for(i=len-1,j=0;i>=k;i--,j++)
{
if(s[i]=='1')
{
last=(last*2+a4[j])%II;
temp=last;
}
else
{
last=(last*2)%II;
}
}
for(i=k-1;i>=0;i--)
temp=(temp*2)%II;
printf("%lld\n",temp); return 0;
}
第四题:
未完待续…………
第五题:
未完待续…………
Codeforces Round #189 (Div. 2)的更多相关文章
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- Codeforces Round #189 (Div. 2) A. Magic Numbers
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- Codeforces Round #189 (Div. 1) C - Kalila and Dimna in the Logging Industry 斜率优化dp
C - Kalila and Dimna in the Logging Industry 很容易能得到状态转移方程 dp[ i ] = min( dp[ j ] + b[ j ] * a[ i ] ) ...
- Codeforces Round #189 (Div. 2) D. Psychos in a Line 单调队列dp
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #189 (Div. 2) A. Magic Numbers【正难则反/给出一个数字串判断是否只由1,14和144组成】
A. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #189 (Div. 1 + Div. 2)
A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- CSS: inline-block的应用和float块高度塌陷
普通流高度塌陷: 当块float浮动时,不会对块布局产生影响,块仍然会按照左右或者上下的顺序排列.但是会影响文档的排列,当文档的高度超过块的高度时,块的高度会产生塌陷现象. 高度塌陷解决方法: ...
- C++基础梳理--Class、Struct、Union
C++学习一段时间后,反过头来看我发现我忘了一下最基础的东西:strcut(结构体),union(联合体)我学会了类的一堆东西却忘了这两个最基础的: 现在就好好的重新学习一下这里的东西: 一.Clas ...
- Tortoisegit 记住用户名和密码
Tortoisegit 记住用户名和密码方法: [Windows系统] 当你配置好git后,在 C:\Documents and Settings\Administrator\ 目录下有一个 .gi ...
- MFC内部结构剖析
//////////////////////////////////////////////////////////////////////////////////////////MFC程序的执行顺序 ...
- VC++非MFC项目中如何使用TRACE宏
记得原来尝试学MFC的时候觉得有一个TRACE可以在Debug时向VS的调试输出窗口输出字串符,用来调试时跟踪变量很方便. 然则如果不是MFC项目或者ATL的项目的话是不能使用这个宏的.这时有一个没有 ...
- ios7下二维码功能的实现
苹果公司升级到IOS7后自己的PassBook自带二维码扫描功能,所以现在使用二维码功能不需要在借助第三方库了 使用前请先导入AVFoundation.frameWork // // YHQView ...
- 孙弘与Masa Maso 做互联网最贵的衬衫(2)_人物对话_中国时尚品牌网
孙弘与Masa Maso 做互联网最贵的衬衫(2)_人物对话_中国时尚品牌网 孙弘与Masa Maso 做互联网最贵的衬衫(2)
- 【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
Result学习笔记(三)带參数的结果集 第一部分:代码 //前端 <head> <meta http-equiv="Content-Type" content= ...
- activity变成Dialog的步骤
1.在布局文件上最外层最好使用RelativeLayout来布局,如果使用LinearLayout来布局的话,显示对话框的话,感觉会有点问题: 要在预览中看到框框,并且是match_parent的,而 ...
- iOS NSRuntime机制
什么是Objective-C runtime? 简单来说,Objective-C runtime是一个实现Objective-C语言的C库.对象可以用C语言中的结构体表示,而方法(methods)可以 ...