A Dreamoon and Stairs 数学水题
题目思路:
判断一下m的倍数的两倍是否大于n.
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
//#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e7+5;
typedef struct node{
int x;
int y;
}NODE;
int n,m;
int main()
{
cin >> n>>m;
for(int i=m;i<=n;i+=m)
{
if(i*2>=n)
{
cout << i<<endl;
return 0;
}
}
cout << -1<<endl;
return 0;
}
B - Dreamoon and WiFi
解题思路:
根据概率,判断’+’号的个数,如果未知字符串的加号的个数小于等于,根据概率进行计算,否则输出-1;
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
//#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e7+5;
typedef struct node{
int x;
int y;
}NODE;
double getnum(int x,int y);
int n;
int num;
int a,b;
string s,s1;
int main()
{
cin >> s;
cin >> s1;
n = s.size();
for(int i=0;i<n;i++)
{
if(s[i]=='+')
a++;
}
for(int i=0;i<n;i++)
{
if(s1[i]=='+')
b++;
else if(s1[i]=='?')
num ++;
}
double re = 0.0;
if(num==0)
{
if(a==b)
{
re = 1.0;
printf("%.9f",re);
//cout << re<<endl;
return 0;
}
else
{
re = 0.0;
printf("%.9f",re);
//cout << re<<endl;
return 0;
}
}
if(b>a)
{
re = 0.0;
printf("%.9f",re);
//cout << re<<endl;
return 0;
}
re = 1.0;
for(int i=0;i<num;i++)
{
re *= 0.5;
}
re *= getnum(num,a-b);
printf("%.9f",re);
//cout << re<<endl;
return 0;
}
double getnum(int x,int y)
{
double re= 1;
for(int i=x;i>x-y;i--)
{
re *= i;
}
for(int i=1;i<=y;i++)
{
re /= (double)i;
}
return re;
}
C - Dreamoon and Sums
解题思路:
先2个for循环暴力,然后根据其进行公式推理。
解题代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
//#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e7+5;
typedef struct node{
int x;
int y;
}NODE;
ull a , b;
ull re = 0;
ull sum = 0,sum1=0,sum2=0;
int main()
{
cin >> a>>b;
/*for(int i = 1;i<=a;i++)
{
for(int j=1;j<b;j++)
{
sum1 += (((i%MOD*j%MOD)%MOD*b%MOD)%MOD+j)%MOD;
sum1 %=MOD;
}
}*/
for(ull i=1;i<b;i++)
{
sum += i%MOD;
sum %=MOD;
}
sum2=sum;
sum = ((sum%MOD)*(a%MOD))%MOD;
ull tt = ((b%MOD)*((sum2)%MOD))%MOD;
for(ull i=1;i<=a;i++)
{
re += ((i*tt)%MOD);
re %= MOD;
}
re += sum;
re %=MOD;
cout << re<<endl;
return 0;
}
D - Dreamoon and Sets 规律题
解题思路:
规律题,先自己找几个数据,然后推出规律
1 2 3 5
7 8 9 11
13 14 15 17
相差为6
解题代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
//#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int N = 1e5+5;
int n,k;
vi re;
int main()
{
int num = 0;
cin >> n>>k;
re.push_back(1);
re.push_back(2);
re.push_back(3);
re.push_back(5);
for(int i=1;i<n;i++)
{
re.push_back(i*6+re[0]);
re.push_back(i*6+re[1]);
re.push_back(i*6+re[2]);
re.push_back(i*6+re[3]);
}
cout << re.back()*k<<endl;
for(int i=0;i<n*4;i+=4)
{
cout << re[i]*k<<" "<<re[i+1]*k<<" "<<re[i+2]*k<<" "<<re[i+3]*k<<endl;
}
return 0;
}