Tody is the last day!
I’ve got 380 scores.
1.
find the answer of “add the top half all (up) numbers and div the last numbers”(100)
It very easy . We can sort the list .(we won’t TLE).
AC:
#include<bits/stdc++.h>
using namespace std;
int item_cnt;
long long mx,items[100010];
int main(){
freopen("problem.in","r",stdin);
freopen("problem.out","w",stdout);
scanf("%d",&item_cnt);
for(int i=0;i<item_cnt;i+=1){
scanf("%lld",&items[i]);
}
sort(items,items+item_cnt);
for(int i=item_cnt-1;item_cnt-i<=item_cnt/2+item_cnt%2;i-=1){
mx=mx-items[item_cnt-i-1]+items[i];
if(item_cnt-i-1==i)mx+=items[i];
}
printf("%lld",mx);
return 0;
}2.
It is a maths problem:
there is x and y
gcd(x,y) = k1
lcm(x,y) = k2
we know all the prime_factor of k1 or k2;
we should count how many kind of value that x and y can be.
1.erase all the prime factor that k1 and k2 both have
2.count how many kind the last prime factor has.
3. answer is pow(2,cnt);
AC:
#include<bits/stdc++.h>
using namespace std;
const long long mo=1e9+7;
int gcdpfac_cnt,lcmpfac_cnt,item;
long long cnt;
multiset<int> lcmfac;
deque<int> gcdfac;
long long pow2(int m){
if(m<1)return 1;
if(m==1)return 2;
if(m%2==0){
long long k=pow2(m/2);
return k*k%mo;
}
long long k=pow2(m/2);
return k*k%mo*2%mo;
}
int main(){
freopen("gcm.in","r",stdin);
freopen("gcm.out","w",stdout);
scanf("%d",&gcdpfac_cnt);
for(int i=0;i<gcdpfac_cnt;i+=1){
scanf("%d",&item);
gcdfac.push_back(item);
}
scanf("%d",&lcmpfac_cnt);
for(int i=0;i<lcmpfac_cnt;i+=1){
scanf("%d",&item);
lcmfac.insert(item);
}
for(int i=0;i<gcdpfac_cnt;i+=1){
lcmfac.erase(lcmfac.find(gcdfac.front()));
gcdfac.pop_front();
}
while(!lcmfac.empty()){
lcmfac.erase(*(lcmfac.begin()));
cnt+=1;
}
if(cnt>0)cnt=pow2(cnt);
else cnt=1;
printf("%lld",cnt);
return 0;
}3.
现在小镇是一个N行M列的方格图,其中第i行第j列未知的a ij.小葱现在从左上角(1,1)出发,走到右下角(N,M),每次走只能朝右或者朝下走。当小葱走到一个格子的时候,小葱能够把当前位置和上下左右五个位置的能量全部吸收。现在小葱想知道整个过程中小葱最多能够吸收多少能量。注意,一个位置的能量被吸收之后,这个位置的能量值就会归零。
It need dp to AC it.
AC codes:
#include<bits/stdc++.h>
using namespace std;
int side1,side2;
int items[1010][1010];
long long dp1[1010][1010];
long long dp2[1010][1010];
int main(){
freopen("energy.in","r",stdin);
freopen("energy.out","w",stdout);
scanf("%d%d",&side1,&side2);
for(int i=1;i<=side1;i+=1){
for(int j=1;j<=side2;j+=1){
scanf("%d",&items[i][j]);
}
}
dp1[1][1]=items[1][1];
dp2[1][1]=items[1][1];
for(int i=1;i<=side1;i+=1){
for(int j=1;j<=side2;j+=1){
if(i!=1 or j!=1){
dp1[i][j]=max(items[i-1][j+1]+items[i][j]+dp1[i-1][j]+items[i][j-1]\
,items[i-1][j+1]+items[i][j]+dp2[i-1][j]);
dp2[i][j]=max(items[i+1][j-1]+items[i][j]+dp2[i][j-1]+items[i-1][j]\
,items[i+1][j-1]+items[i][j]+dp1[i][j-1]);
}
}
}
printf("%lld",max(dp1[side1][side2],dp2[side1][side2]));
return 0;
}4.
Ho. I don’t like to write the question in English..
小葱想要知道是否存在一个公差为x的无穷长度的等差数列,使得这个等差数列不存在任何一个斐波那契数。
1.if in the number list there is a number is in Fib so,等差数列’s first number is the number in Fid mod 差.
So the f(n)%k = ( f(n-1)%k +f(n-2)%k )%k
So we can 遍历 the number that can find in Fid(i)%k
80 Scores codes:
#include<bits/stdc++.h>
using namespace std;
int x;
int main(){
freopen("fibonacci.in","r",stdin);
freopen("fibonacci.out","w",stdout);
scanf("%d",&x);
if(x<10 and x!=8)printf("0");
else if(x==8)printf("2");
else {
int cnt=0;
for(int i=4;i<x;i+=1){
int xx=0,yy=1;
long long ccnt=1,nx=0,ny=1;
set<vector<int> > t;
bool flag=1;
while(1LL*ccnt<1LL*x*x and (xx!=nx or ny!=yy or ccnt==1)){
if(nx==i or ny==i){
flag=0;
break;
}
int temp=nx;
nx=ny;
ny=(1LL*ny+temp)%x;
if(nx==i or ny==i){
flag=0;
break;
}
ccnt+=1;
}
if(flag)cnt+=1;
}
printf("%d",cnt);
}
return 0;
}AC codes:
#include<bits/stdc++.h>
using namespace std;
int x;
bool is_has[1000010];
int main(){
freopen("fibonacci.in","r",stdin);
freopen("fibonacci.out","w",stdout);
scanf("%d",&x);
if(x<10 and x!=8)printf("0");
else if(x==8)printf("2");
else {
long long cnt=0,c=0;
int t1=0,t2=1;
is_has[t1]=1;
is_has[t2]=1;
do{
c+=1;
int temp=t1;
t1=t2;
t2=(temp+t2)%x;
is_has[t1]=1;
is_has[t2]=1;
}while((t1!=0 or t2!=1) and c<=1LL*x*x);
for(int i=4;i<x;i+=1){
if(is_has[i]==0)cnt+=1;
}
printf("%d",cnt);
}
return 0;
}the work is end! Yihi!