题目地址: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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #189 (Div. 2) A. Magic Numbers

    #include <iostream> #include <vector> #include <algorithm> #include <string> ...

  3. 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 ] ) ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #189 (Div. 1 + Div. 2)

    A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二 ...

  7. 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 ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Light OJ 1104 Birthday Pardo(生日悖论)

    ime Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description Sometime ...

  2. 【Visual C++】游戏开发五十六 浅墨DirectX教程二十三 打造游戏GUI界面(一)

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/16384009 作者:毛星云 ...

  3. GNU scientific library

    GNU scientific library 是一个强大的C,C++数学库.它涉及的面很广,并且代码效率高,接口丰富.正好最近做的一个项目中用到多元高斯分布,就找到了这个库. GNU scientif ...

  4. 查询sql语句耗时的方法!

    declare @times datetimeset @times=getdate()--要查询的sql语句select [注册数花费时间(毫秒)]=datediff(ms,@times,getdat ...

  5. 通过原生js的ajax或jquery的ajax获取服务器的时间

    在实际的业务逻辑中,经常是与时间相关的,而前端能获得的时间有两个:客户端的时间,服务器的时间. 客户端时间通过 javascript中的Date对象可以获取,如 var dt = new Date() ...

  6. hibernate Annotation 以及注解版的数据关联 4.4

    目的是不写xxx.hbm.xml映射文件,使用注解 主配置文件还是要有hibernate.cfg.xml <?xml version="1.0" encoding=" ...

  7. Linux 各类软件整理汇总

    关于前端和后端的解释 详细链接见:http://wiki.ubuntu.org.cn/Qref/Apps Linux下程序通常不需要作为一个整体,而是模块化,于是有了可选的前端和后端——这种情况下:前 ...

  8. Python用subprocess的Popen来调用系统命令

    当我们须要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.可是这两个命令过于简单,不能完毕一些复杂的操作,如给执行的命令提供输入或者读取命令的输出, ...

  9. Java数据类型BooleanDemo

  10. 在AD09中查找元件和封装

    在AD09中查找元件和封装 Altium Designer 软件方法/步骤 Altium下Miscellaneous Devices.Intlib元件库中常用元件有: 电阻系列(res*)排组(res ...