这一场……我终于进入紫名了~
这一场……ABD写的挺快的……然后就有点自负了想要去写写E题……结果把C给放弃了……真是可惜……
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
int main()
{
int n,m; cin>>n>>m;
int steps=n%2+n/2;
if(n==0){cout<<"0"; return 0;}
if(steps%m!=0) steps+=(m-steps%m);
if(steps>n) steps=-1;
cout<<steps; return 0;
}
B. Dreamoon and WiFi
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
- Go 1 unit towards the positive direction, denoted as '+'
- Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.
++-+- +-+-+
1.000000000000
+-+- +-??
0.500000000000
+++ ??-
0.000000000000
For the first sample, both s1 and s2 will lead Dreamoon to finish at the same position + 1.
For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, s2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0.
这道题是说,先给一个左右移动的字符串,+是右移,-是左移,然后第二个字符串(其中可能有问号代表不知道这里是+还是-),问这个字符串到达第一个字符串移动的终点的概率是多少。那么很显然,如果第二个字符串没有问号,那就是直接判断位置,概率那就是1或0,每出现一个问号就多一个不确定项。我们先把可以确认的移动方向去定下来,看还距离多少,看剩下的问号数有没有可能完成剩下的任务(问号比剩余距离短或者达成目标之后剩余的问号数不是偶数),顺便说一下,为啥达成目标之后剩余需要是偶数呢,因为可以一个加号一个减号抵消掉呀~
so,那就是个简单概率题咯~,通过计算,问号们应该是几个+几个-才可以完成,那么就直接C(all,need)*1/(2^all)即可^_^
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int Jc[12];
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
void Jc_init()
{
Jc[1]=Jc[0]=1;
for(int i=2;i<12;i++)
Jc[i]=Jc[i-1]*i;
}
double C(int n,int m)
{
double ret=1.0;
for(int i=1;i<=n;i++) ret/=2.0;
ret= ret*(double)Jc[n]/(double)Jc[m]/(double)Jc[n-m];
return ret;
}
int main()
{
string s1,s2;
cin>>s1>>s2;
double rate=0.0;
int pos1=0,pos2=0,unc=0;
Jc_init();
for(int i=0;i<s1.length();i++)
{
if(s1[i]=='+')pos1++;
else pos1--;
if(s2[i]=='+')pos2++;
else if(s2[i]=='-') pos2--;
else unc++;
}
int pos=abs(pos2-pos1);
if(pos<=unc)
{
int res=unc-pos;
if(res%2==0)
{
int need=res/2+pos;
rate=C(unc,need);
}
}
printf("%.12f",rate);
return 0;
}
C. Dreamoon and Sums
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if and , where k is some integer number in range [1, a].
By we denote the quotient of integer division of x and y. By we denote the remainder of integer division of x andy. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
1 1
0
2 2
8
For the first sample, there are no nice integers because is always zero.
For the second sample, the set of nice integers is {3, 5}.
===》
范围内满足这些各项范围条件内的,满足条件的x的和是多少
这道题是当时没能写出来的题……
数学要学好哇,推公式挺重要……
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll lim=(ll)1e9+7;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
int main()
{
ll n,a,b;
const ll mod=1000000007;
scanf("%I64d%I64d",&a,&b);
if(b==1){printf("0\n");return 0;}
ll fa,fb,an=(b+1+b*a+1)*a/2;
ll ans=((a*(a+1)/2)%mod*b+a)%mod;
ans=ans*((b*(b-1)/2)%mod)%mod;
printf("%I64d\n",ans);
return 0;
}
Python_Code:
a, b = tuple(map(int, input().split()))
print((b*(b-1)*a*(a+1)*b//4 + a*b*(b-1) // 2) % 1000000007)
这道题的意思是请找出n组数,每组4个数,要求每组的4个数字两两之间的公约数都是k……
那我们就弄成每组数字都互质,然后全体乘以k不就行了么……
然后看了看样例……
这个该怎么说……我是觉得额这道题的output暴露了数据规律怎么破……我算是看出规律再证明的方式A的这道题当时我看到22那个样例的时候……在想他干嘛要把22放这里……然后发现 2/4/6/10 14/16/18/22也是行的哇……
化成乘以k之前的数据…… 1/2/3/5和7/8/9/11……我就试了试——每组公差都是6?……然后就A了……
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
int main()
{
int n,k; cin>>n>>k;
int v[4]={1,2,3,5};
printf("%d\n",(n*6-1)*k);
for(int i=1;i<=n;i++)
{
for(int j=0;j<4;j++)
{
if(j==0) printf("%d",v[j]*k);
else printf(" %d",v[j]*k);
v[j]+=6;
}
printf("\n");
}
return 0;
}