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”三种中任意一种就输 ...
随机推荐
- ;(function($,window,undefined){})(jQuery,window)详细解析————借助B5教程解析自己整理了一下
在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...
- linux命令: patch
一. 针对单文件的patch: 我们以mkprj.sh.1和mkprj.sh两个文件为例: [root@localhost tst]# lsmkprj.sh.1 mkprj.sh 看两个文件的差异: ...
- 我的Python成长之路---第八天---Python基础(23)---2016年3月5日(晴)
socketserver 之前讲道德socket模块是单进程的,只能接受一个客户端的连接和请求,只有当该客户端断开的之后才能再接受来自其他客户端的连接和请求.当然我们也可以通过python的多线程等模 ...
- 接收串口数据0x00 strlen函数会截断
写个串口接收程序接收到之后,用了一个上strlen,结果数据不全了,百度了下 strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域) ...
- [WPF疑难]如何禁用窗口上的关闭按钮
原文 [WPF疑难]如何禁用窗口上的关闭按钮 [WPF疑难]如何禁用窗口上的关闭按钮 周银辉 哈哈,主要是调用Rem ...
- 修改MojoWeixin 只保留用户name 取消群昵称
<pre name="code" class="python"> if($msg->type eq "friend_message& ...
- UI 公钥加密
RSA算法是一种非对称加密算法,常被用于加密数据传输.如果配合上数字摘要算法, 也可以用于文件签名. 本文将讨论如何在iOS中使用RSA传输加密数据. RSA基本原理 RSA使用"秘匙对&q ...
- OTN交换&P-OTN有效减少100G网络成本(一)
近年来.网络运营商一直严重依赖基于ROADM的光传送设备,利用固定的点到点WDN联接.利用10G波长在整个城域网和广域网中汇聚及传送client业务.假设这些网络经过精细的设计规划,也能够合理.有效地 ...
- ActionBar点击弹出下拉框操作
首先: getActionBar().setDisplayShowTitleEnabled(false); ActionBar.LayoutParams lp = new ActionBar.Layo ...
- windows下取linux系统里面的文件
方法一:使用原生态的psftp 1.下载psftp.exe http://pan.baidu.com/s/1boVLHKF 2.双击psftp.exe 2.1 输入指令:open IP地址 (例如:o ...