A
给出一个数n,找到3个数a,b,c,a,b,c均能整除n,使得n = a+b+c且a*b*c最大,找不到a b c就输出-1
令 x = n/a y = n/b z = n/c 公式同时除以n--->1 = 1/x+1/y+1/z -- >3个解 (3,3,3)(2,4,4),(2,3,6)
当n%3 == 0--> x*y*z = n^3/27
n%4 == 0 -->x*y*z = n^3/32
n%6 == 0 -->x*y*z = n^3/36<n^3/27 = n^3/27
其他情况为-1
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
int t;
long long n;
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
if(n % 3 == 0)
printf("%lld\n",n*n*n/27);
else if(n % 4 == 0)
printf("%lld\n",n*n*n/32);
else
cout<<"-1\n";
}
return 0;
}
C
给出3*n个不共线的点,组合出n个三角形,求n个三角形的三个坐标的顺序
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
int x,y,num;
bool operator< (const node& a) const{
return x<a.x || x==a.x&&y<a.y;
}
}a[300006];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = 1;i<=3*n;++i){
scanf("%d%d",&a[i].x,&a[i].y);
a[i].num = i;
}
sort(a+1,a+1+3*n);
int j = 1;
for(int i = 1;i<=n;++i){
cout<<a[j].num<<" "<<a[j+1].num<<" "<<a[j+2].num<<endl;
j += 3;
}
}
return 0;
}
Chiaki Sequence Revisited找规律,a1 = a2 = 1,an = a n-an-1 + a n-1-an-2
|
#include<iostream>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
LL n;
bool judge(LL mid,LL n){
LL ans = 0;
while(mid > 0)
ans += mid,mid >>= 1;
return ans >= n;
}
const LL inv2 = 500000004;
const int maxn = 1e6;
LL a[maxn];
LL an[maxn];
LL F(LL n){
if(n < 200){
return a[n];
}
n--;
LL l = 1,r = n;
while(r >= l){
LL mid = l+((r-l)>>1);
if(!judge(mid,n))
l = mid+1;
else
r = mid-1;
}
LL ans = 0;
LL num = 0;
while( r > 0)
num += r, r >>=1;
num = n-num;
ans = (num%mod*(l%mod))%mod;
l--;
LL tmp = 1;
while(1){
LL t = l/tmp;
if(t & 1)
t = t%mod*(((t+1)/2)%mod)%mod;
else
t = (t/2)%mod*((t+1)%mod)%mod;
ans = (ans+(t*(tmp%mod)%mod))%mod;
tmp <<= 1;
if(tmp > l)
break;
}
return (ans+1)%mod;
}
int main(void)
{
a[1] =a[2]= 1;
for(int i = 3;i < maxn; ++i)
a[i] = (a[i-a[i-1]]+a[i-1-a[i-2]])%mod;
for(int i = 1;i < maxn;++i)
a[i] = (a[i] +a[i-1])%mod;
int T;
scanf("%d",&T);
for(int i = 1;i <= T; ++i){
scanf("%lld",&n);
LL ans = F(n);
printf("%lld\n",ans);
}
return 0;
}