table of Contents
A- games
The meaning of problems
Two people in the stone scissors cloth, two people know a number of rock-paper-scissors
seeking the first person to win the most number of times
Thinking
Is min (a rock, scissors 2) + min (1 cloth, stone 2) + min (1 scissors, cloth 2)
Code
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long a1,a2,a3;
long long b1,b2,b3;
cin>>a1>>a2>>a3>>b1>>b2>>b3;
long long sum=0;
sum+=min(a1,b2)+min(a2,b3)+min(a3,b1);
cout<<sum<<endl;
}
B- row of numbers
The meaning of problems
Coke was a pure bovine numeric string \ text {} SS, he would like to know can be any upset \ text {} case SS sequence, up to how many different substring \ text {616} 616.
Thinking
Count the number of 1 and 6,
when the 61616 as can
a 6 may be used when the sides
if is greater than 6 then the number is a number of 1
if the number 6 is equal to 16,161 minus 1 is the number 1
if 6 is less than the number 1616116161611 6 number minus 1
Code
#include<string>
using namespace std;
int main()
{
int n;
string s;
cin>>n>>s;
int sum6=0;
int sum1=0;
for(int i=0;i<n;i++)
{
if(s[i]=='1')
sum1++;
if(s[i]=='6')
sum6++;
}
int ans;
if(sum1<sum6)
ans=sum1;
else
{
if(sum1==sum6)
ans=sum1-1;
else
ans=sum6-1;
}
cout<<ans<<endl;
return 0;
}
C- count probability
The meaning of problems
You n track title, the right to know the probability of each question, the i-channel is p [i, respectively, to obtain the title track, there are n 0,1,2,3, n Road probability are entitled to do
Thinking
With a two-dimensional array f [i] [j] represents the i questions, there are questions to do j probability, you know f [i] [j] have to know f [i]
[0], seeking f [i] [0] i represents 0 for questions make the whole is wrong, that is, the probability of questions before i-1 multiplied by the probability of the wrong questions wrong i is f [i-1] [o ] (. 1-P [i]), then ask questions which do i j probability questions, the method is: the two cases are divided into i to questions do not do, that is, f [i] [j F] = [. 1-i] [J] (. 1-P [i]) + F [i] [-J. 1] P [i]
of the i-type sense probability wrong question. In order to facilitate the calculation, we assume all fractional a / b b which denominator is 1, i.e., b = 1, (because any fractional denominator can be transformed to equation 1, of course, the molecule may be a decimal. Therefore, the B Q% (+ 1E9. 7) = a; where b = 1, q is our input p [i], available p [i] = kmod + a ; i.e. a = p [i] -kmod; then probability of error is required with the corresponding 1-a, i.e., 1-a = (kmod + 1 -p [i])% mod = (mod + 1-p [i])% mod, because the denominator b is 1;
Code
#include<iostream>
const int mod=1e9+7;
long long p[2020],f[2020][2020];
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)//(mod+1-p[i])%mod 为做错的概率
cin>>p[i];
f[0][0]=1;//0道题目做对0道的概率肯定是1;
for(int i=1;i<=n;i++)
{f[i][0]=f[i-1][0]*(mod+1-p[i])%mod;//求i道题目做对0道的概率
//也就是全做错的gai概率就是前i-1道全做错再乘第i道做错的概率
for(int j=1;j<=i;j++)
f[i][j]=(f[i-1][j]*(mod+1-p[i])%mod+f[i-1][j-1]*p[i])%mod;
//求i道题目作对j道的概率分两种情况一种是第i道没做对,就是
//前i-1道做对j道的概率再乘以第i道,没做对的概率
//还有一种情况就是第j道做对了概率就是 前i-1 道做对j-1道的概率再乘以第i道做对的概率
}
for(int i=0;i<=n;i++){
cout<<f[n][i];
if(i<n) cout<<" "; //为了按题目格式输出,希望这个方法还没学到的同学可以记住
}
return 0;
}
D. triangular number
The meaning of problems
N give you points, given their coordinates, and asked how many obtuse triangle can be constructed
Thinking
Using the vector product of two vectors is less than 0 then their angle greater than 90 degrees but it is to be noted that the case of collinear, violence enumerated three points, the three points are required angle is an obtuse angle so long as there is a obtuse triangle
Code
#include<iostream>
using namespace std;
int x[510],y[510];
bool juge(int a,int b,int c)
{
int res1=x[b]-x[a];
int res2=y[b]-y[a];
int res3=x[c]-x[a];
int res4=y[c]-y[a];
if(res1*res3+res2*res4<0&&res1*res4!=res3*res2)
return true;
return false;
}//对于两个向量(a1,b1)(a2,b2)如果两个向量的积小于0即a1*a2+b1*b2<o
//那么两个向量的夹角就小于0但是要注意共线的情况
//a1*b2=b1*a2 两向量共线
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x[i]>>y[i];
int ans=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
for(int k=j+1;k<=n;k++)
if(juge(i,j,k)||juge(j,i,k)||juge(k,i,j))
ans++;
cout<<ans<<endl;
return 0;
}
E. do count
The meaning of problems
And then find a number n to the number of such triples satisfying (i, j, k), satisfying sqrt i + sqrt j = sqrt k, and satisfies i * j <n, as long as there is a number of different ijk said to be a different triplets (ijk all integer)
Thinking
See square root to obtain
2 sqrt (i J) = KJI, are integers so as ijk 2 sqrt (J J) is an integer, so i squared j = m and m is less than n side so i J is the number of a square, That i, j is the square of the said factors, the number of violent enumerate demand factors on it
Code
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
int ans=0;
cin>>n;
for(int i=1;i<=sqrt(n);i++)
{
int k=i*i;
for(int j=1;j<=sqrt(k);j++)
{
if(j==i)ans+=1;
else
if(k%j==0)ans+=2;
}
}
cout<<ans<<endl;
return 0;
}
F. to take items
The meaning of problems
Given the n goods, there are two attributes ai, bi, two take turns can only take a, ai the first person close to harvest, bi, and for the second person gains
two people want to own try to score bigger than the other (ie, to maximize their own and each other's score difference).
You need to find a case where both using the optimal strategy, and ultimately will choose which items are, if multiple answers or output order, output either.
Thinking
At the same time there is a commodity ai bi, this question is actually not see the difference between ai and bi are very small because if 11 took useless, that question you take an item contains both ai and bi you took your ai bi rivals lost, so you earn harvest is ai + bi so the best strategy is to get ai and bi and the biggest, so the topic is solved
Code
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200010;
struct node1
{
int pos1,pos2;
} a[maxn];
struct node2
{
int pos,key;
}b[maxn];
bool cmp(node2 x,node2 y)
{
return x.pos>y.pos;//从大到小排序
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].pos1;
for(int i=1;i<=n;i++)
cin>>a[i].pos2;
for(int i=1;i<=n;i++)
{
b[i].pos=a[i].pos1+a[i].pos2;
b[i].key=i;
}
sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++)
if(i&1)
cout<<b[i].key<<" ";
cout<<endl;
for(int i=1;i<=n;i++)
if(i%2==0)
cout<<b[i].key<<" ";
cout<<endl;
return 0;
}
G- judge right and wrong
The meaning of problems
Coke bovine seven integers a, b, c, d, e, f, g and a d-th power of his guess a + b + d e th and f th = g holds
. But such a large Coke cattle can not be calculated.
Please verify cattle cola conjecture holds.
Thinking
Fast power, but be aware that mold and once again add value into a number of years, do not add up full-time judge, or do not know why wow
Code
#include<iostream>
const int MOD=1E9+7;
using namespace std;
typedef long long ll;
ll quick_pow(ll a, ll b) {
if(a == 0)
return 0;
if(b == 0)
return 1;
ll ans = 1;
ll base = a % MOD;
while(b) {
if(b & 1)
ans = (ans * base) % MOD;
base = (base * base) % MOD;
b >>= 1;
}
return ans;
}
int main()
{
ll a,b,c,d,e,f,g,t;
cin>>t;
while(t--)
{
cin>>a>>b>>c>>d>>e>>f>>g;
ll ans=0;
ll x;
x=quick_pow(a,d);
ans+=x;
x=quick_pow(b,e);
ans+=x;
x=quick_pow(c,f);
ans+=x;
if(ans==g)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}