题目地址: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. SQL中distinct的用法(转)

    原文:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...

  2. java的大数类

    java中的大数类,真的很方便,不用自己再写计算的函数,先写一个简单的例子,以后再补充 注意大数初始化的时候,参数十字符型的,如果传进去的变量十一个数字,需要加上一个空字符即:+"" ...

  3. atexit模块解析

    atexit模块很简单,只定义了一个register函数用于注册程序退出时的回调函数,我们可以在回调函数中做一些资源清理的操作. 注意回调函数只有正常退出的时候才会调用,如果程序是被信号杀死或者因为严 ...

  4. tf–idf算法解释及其python代码实现(下)

    tf–idf算法python代码实现 这是我写的一个tf-idf的简单实现的代码,我们知道tfidf=tf*idf,所以可以分别计算tf和idf值在相乘,首先我们创建一个简单的语料库,作为例子,只有四 ...

  5. php基本框架

  6. 配置 .vimrc 解决 Vim / gVim 在中文 Windows 下的字符编码问题

    转载自:-杨博的日志 - 网易博客 Vim / gVim 在中文 Windows 下的字符编码有两个问题: 默认没有编码检测功能 如果一个文件本身采用的字符集比 GBK 大(如 UTF-8.UTF-1 ...

  7. Qt在windows 平台操作保存execel的表格(通过QAxObject来操作)

    粗略操作 QT += core gui sql CONFIG += qaxcontainer greaterThan(QT_MAJOR_VERSION, 4): QT += widgets #incl ...

  8. VC6中创建Qt工程的创建

    文章来源:http://blog.sina.com.cn/s/blog_64d015c10100sf1o.html 本文主要介绍怎么创建可以在VC6中编译的QT工程.本文所采用环境为VC++6.0+Q ...

  9. BZOJ 1603: [Usaco2008 Oct]打谷机

    题目 1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John有一个过时的打谷机( ...

  10. 你喜欢SOAP吗?反正我不喜欢!

    叫什么Simple Object Access Protocol,实际上一点都不Simple! 说什么轻量级协议,从它基于XML的编码就知道它有多臃肿! 说什么跨平台特性,其实各个语言需要自己实现一整 ...