Codeforces Round #272 (Div. 2)
A. Dreamoon and Stairs
题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数
找出范围,即为最大步数为n(一次上一级),最小步数为n/2+n%2 在这个范围里找即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL; int main()
{
int n, m,i,flag=,mn,mx;
cin>>n>>m;
mx=n;
mn=n/+n%; for(i=mn;i<=mx;i++){
if(i%m==) {
flag=;
printf("%d\n",i);
break;
}
}
if(!flag) printf("-1\n");
}
B. Dreamoon and WiFi
题意:给出两个字符串s1,s2 s1中只包含'+','-'(+代表加1,-代表-1) s2中包含'+','-','?'三种, 问s1,s2串得到相同的数值的概率
在s1中,令a[0]表示-,a[1]表示+
在s2中,令b[0]表示-,b[1]表示+,b[2]表示问号
分问号的个数为0和不为0来讨论
问号为0是:分别判断加号,减号的个数是否相等即可
问号不为0是,那么所差的加号为a[1]-b[1],即为从b[2]个位置中选出a[1]-a[0]个位置,再用这个除以总的方案数2^b[2]
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
char s1[],s2[],a[],b[]; LL C(int n,int m){
if(n<m||n<||m<) return ;
if(m<n-m) m=n-m;
LL ans=;
for(int i=m+;i<=n;i++) ans*=i;
for(int i=;i<=n-m;i++) ans/=i;
return ans;
} int main()
{
int len1,len2,i,j,pos,pos1,tot,sum,sum1;
cin>>s1>>s2;
len1=strlen(s1);
len2=strlen(s2); // printf("c(2,3)=%d\n",C(2,3)); for(i=;i<len1;i++){
if(s1[i]=='+') a[]++;
if(s1[i]=='-') a[]++;
}
for(i=;i<len2;i++){
if(s2[i]=='+') b[]++;
else if(s2[i]=='-') b[]++;
else b[]++;
}
if(b[]==){
if(a[]==b[]&&a[]==b[]) printf("1.000000000000\n");
else printf("0.000000000000\n");
}
else{
pos1=a[]-b[];
pos=b[];
tot=;
for(i=;i<=pos;i++)
tot*=;
double ans=(C(pos,pos1)*1.0)/tot;
printf("%.12lf\n",ans);
}
return ;
}
C. Dreamoon and Sums
题意:给出a,b,找出符合以下条件的x,div(x,b)/mod(x,b)=k,其中k所在范围是[1,a],其中mod(x,b)!= 0.求满足这样的条件的x的和
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
LL mod=; int main()
{
LL a,b;
cin>>a>>b;
LL ans1=(a*(a+)/%mod*b%mod+a)%mod;
LL ans2=b*(b-)/%mod;
LL ans3=ans1*ans2%mod;
cout<<ans3<<"\n";
}
c是= =翻译的题解----
Codeforces Round #272 (Div. 2)的更多相关文章
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...
- Codeforces Round #272 (Div. 2)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #272 (Div. 1) B 构造 math
http://www.codeforces.com/contest/477/problem/C 题目大意:给你n个集合,每个集合里面有四个数字,他们的gcd是k,输出符合条件的集合中m,m为集合中最大 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp
B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...
随机推荐
- 一些牛逼的统计SQL
SQL 1.查询连续2天,每天发帖大于等于2次的用户 SELECT USER_ID FROM ( SELECT USER_ID, DATEDIFF(CREATE_TIME, '1971-01-01') ...
- html——a标签添加点击事件,火狐浏览器直接显示0
一.问题描述 给一个a标签添加了点击事件,页面直接给了0如下图 二.问题解决 后台调试模式下,发现也进了后台方法,也返回了页面. 于是想到先把页面里大部分内容去掉,去掉所有js,查看是否是部分代码有问 ...
- [转载]JS中如何定义全局变量
三种方法 1.在js的function外定义一个变量 var name='测试'; function XX(){ alert(name); } 2.不使用var,直接给定义变量,隐式的声 ...
- XML注入介绍--XXE,XEE,xpath等
XML注入指在请求的XML中插入攻击利用代码.根据不同的场景,可能会形成以下的漏洞形式: (1)XEE ----xml entity xpansion(xml实体膨胀,用于dos) 具体介绍:http ...
- 建立docker私有hub
docker是一个非常好用的虚拟化工具. 下面给出建立私有docker hub的方法.docker将私有hub的环境打包在registry image中 执行指令: docker run -p 500 ...
- poj 1006 生理周期(中国剩余定理)
题目 题目有中文翻译,自行查看. 中国剩余定理,基础的,但是我最早还是一窍不通,后来看了各种网上的博客上的相关解析,终于有点懂了,下面这个链接是让我懂得蛮多的一个博客,虽然大体上和其他的差不多. 代码 ...
- POJ 1577 Falling Leaves (子母二叉树,给出叶子节点的删除序列,求前序遍历)
题意:给出一棵字母二叉树删除叶子节点的序列,按删除的顺序排列.让你输出该棵二叉树额前序遍历的序列.思路:先把一棵树的所有删除的叶子节点序列存储下来,然后从最后一行字符串开始建树即可,最后遍历输出. ...
- Git 使用方法
Git 常用命令 git init here -- 创建本地仓库(repository),将会在文件夹下创建一个 .git 文件夹,.git 文件夹里存储了所有的版本信息.标记等内容 git remo ...
- Nodejs常见安装
1.Windows 下成功安装node-canvas2.jsdom——node.js的DOM
- IIS常见错误及解决
IIS常见错误 1.HTTP 错误 404.3 - Not Found由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. 解决办法: w ...