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 ...
随机推荐
- C++拷贝构造函数详解(转载)
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员 ...
- pure.css
注释中address是纠正的意思 等价于correct/*! Pure v0.5.0 Copyright 2014 Yahoo! Inc. All rights reserved. Licensed ...
- 【转载】hadoop的版本问题
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:阿笨猫 原文地址:http://www.cnblogs.com/xu ...
- HDU 2821 Pusher
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关 ...
- oracle——DDL
一.一些概念 定义: 主键--唯一标识一条记录,不能有重复的,不允许为空 外键--表的外键是另一表的主键, 外键可以有重复的, 可以是空值 索引--该字段没有重复值,但可以有一个空值 作用: 主键-- ...
- 关于vs2010 起始页
vs2010 起始页不显示怎么解决 工具 ---> 选项---->环境---->启动---->启动时(选项框),然后点击框尾的下拉三角按钮,点选"显示起始页" ...
- 01-08-04【Nhibernate (版本3.3.1.4000) 出入江湖】二级缓存:NHibernate自带的HashtableProvider之命名缓存
http://www.cnblogs.com/lyj/archive/2008/11/28/1343418.html 可以在映射文件中定义命名查询,<query>元素提供了很多属性,可以用 ...
- 《head first java 》读书笔记(四)
Updated 2014/04/09 P518--P581 <数据结构> ArrayList不能排序:TreeSet以有序状态保持并可防止重复.HashMap可用成对的name/value ...
- NameValueCollection详解
1.NameValueCollection类集合是基于 NameObjectCollectionBase 类. 但与 NameObjectCollectionBase 不同,该类在一个键下存储多个字符 ...
- 拼写sql语句随笔
DECLARE @str NVARCHAR(1000)='SELECT * FROM dbo.V_MicroUserInfo ',@where VARCHAR(1000)=' where 1=1' D ...