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”三种中任意一种就输 ...
随机推荐
- Linux下Apache服务器并发优化
Linux/UnixLinux系统下Apache 并发数的优化 Apache Http服务器采用prefork或者是worker两种并发控制模式. preforkMPM 使用多个子进程,每个子进程只 ...
- VS2010 .net4.0 登录QQ 获取QQ空间日志 右键选中直接打开日志 免积分 源码下载
代码有一部分是原来写的 最近翻代码 看到了 就改了一下 CSDN上传源码 上传了几次都没 成功 郁闷 不知道怎么回事 上传不了 想要的留 邮箱 或加群77877965 下载地址在下面 演示地址 ...
- [LeetCode]题解(python):019-Remove Nth Node From End of List
题目来源: https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 题意分析: 这道题是给定一个链表,删除倒数第n个节点.提醒, ...
- C语言之猜数字游戏
猜数字游戏 猜数字游戏是以前功能机上的一款益智游戏,计算机会根据输入的位数随机分配一个符合要求的数据,计算机输出guess后便可以输入数字,注意数字间需要用空格或回车符加以区分,计算机会根据输入信息给 ...
- nfs:server is not responding,still trying 原因与解决
方案(学自他人) nfs:server is not responding,still trying的解决方法 (2009-04-20 10:20) 方法1 : 我在arm上通过NFS共享文件时出现下 ...
- 转:seajs的spm使用摸索
~~~spm是基于nodejs的,打开nodejs命令行工具,npm install spm -g 进行spm的安装,过程很漫长 github上的官网不能访问 seajs自带的spm打包工具相关文档略 ...
- 这些屌炸天的创业者为何对投资人说NO
曾有人说,世上的创业者只分为两种,一种是找到投资的,一种是没有找到的. 但其实还有第三种,就是那些拒绝了投资人的创业者. 他们摒弃了投资人抛来的橄榄枝,并非不差钱,不接受投资的原因大体出于两个方面,一 ...
- synapse socket总结三:心跳(Heartbeat)
首先转载一篇关于心跳的博文解释: 所谓的心跳包就是客户端定时发送简单的信息给服务器端告诉它我还在而已.代码就是每隔几分钟发送一个固定信息给服务端,服务端收到后回复一个固定信息如果服务端几分钟内没有收到 ...
- Qt学习 之 多线程程序设计(QT通过三种形式提供了对线程的支持)
QT通过三种形式提供了对线程的支持.它们分别是, 一.平台无关的线程类 二.线程安全的事件投递 三.跨线程的信号-槽连接. 这使得开发轻巧的多线程Qt程序更为容易,并能充分利用多处理器机器的优势.多线 ...
- python list comprehension twos for loop 嵌套for循环
list comprehension 后面可以有多个for loops,每个for后面可以有if [(x, y, x * y)for x in(0,1,2,3)for y in(0,1,2,3)if ...