1003 VC Is All You Need
Problem Description
Three points example.
Four points example.
In this picture you can draw a line to seperate these 3 points in the
two dimensional plane to keep points with the same color lie in the
same side no matter how to color each point using either blue or red.But in k dimensional real Euclidean space Rk, can you find n points
satisfying that there always exsit a k−1 dimensional hyperplane to
seperate them in any one of 2n coloring schemes?
Input
The first line contains only one integer T(1≤T≤105) denoting the number of test cases.Each of next T lines contains two integers n,k∈[2,1018] seperated by a
space.
Output
Print Yes if you can find one solution, or print No if you cannot.
大意:
给你n个点和一个k维空间,问你是否存在一个k-1维得超平面,使得对于所有n个点的所有不同的颜色组合,该平面可以使不同颜色的点分开。
n维空间中,求m的最大值,使得你可以找到个点(自己给定坐标),满足:
无论对m这个点如何二染色,也就是对于2^m种染色方案中的每一种,都总存在一个n-1维超平面,严
格分开这两种颜色的点。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
if(n-k <= 1)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
}
1006 Cute Tree
Problem Description
Given the pseudo-code of a function Build−Tree(A,id,L,R):
where A is given in input, id is the number of node, L ,R is the left position and the right position of A
Require the number of nodes created by Build−Tree(A,root,1,n).
Input
The first line contains an integer T (1≤T≤5) representing the number
of test cases.For each test case, the first contain one integer n(1≤n≤2∗105).
The second line contain n integers Ai(1≤Ai≤109).
Output
For each test output one line, the number of nodes created by Build−Tree(A,root,1,n).
记忆化搜索
按题意模拟即可,输出树的节点个数即可
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int N=1e5+10;
map<ll,ll>mp;//记录着他的区间大小
ll find(ll n){
if(mp[n]!=0) return mp[n];
if(n==1)return mp[n]=1;
else if(n==2)return mp[n]=3;
//这个时候就只有左子树、右子树、根
else{//这一部分是根据题意来的
int b=n/3;
if(n%3!=0)b++;
int c=n-b>>1;
return mp[n]=1+find(b)+find(c)+find(n-b-c);
}
}
int main()
{
int t;
cin>>t;
while(t--){
mp.clear();
ll n;
int x;
cin>>n;
for(int i=0;i<n;i++){
scanf("%d",&x);
}
cout<<find(n)<<endl;
}
return 0;
}
1007 Banzhuan
** Problem Description**
Given a three-dimensional space of [1,n]×[1,n]×[1,n]. You’re required
to place some 1×1×1 cubes to make this 3D space look n×n square from
above, from left and from front, while the plane xOy stand for the
ground and z axis describes the height.But placing these cubes must follow some restrictions. Obviously, it
must obey the gravity laws. It means, when beneath a cube is empty,
the height of this cube will drop one, until its height is exactly 1
(touch the ground) or there is another cube below it.And besides that, placing cubes has some prices. If a cube is placed
at an integer coordinate (x,y,z), the price will be x×y2×z.Now, satisfying all the requirements above, you’re required to
calculate the minimum costs and the maximum costs.
Input
The first line contains an integer T(T≤15). Then T test cases follow.For each test case, input a single integer n per line, while
satisfying 1≤n≤1018.
Output
For each test case, output two lines. For the first line output the minimum costs mod 109+7. And for the second line, output the maximum costs mod 109+7.
由于我太菜了,这里引用另一位大佬的博客https://blog.youkuaiyun.com/ANTFANAAA/article/details/119361296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
const int inf=0x3f3f3f3f;
const int p=1e9+7;
ll qpow(ll a,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*a%p;
n>>=1;
a=a*a%p;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// for(int i=1;i<=10;i++)
// {
// ll ans=0;
// for(int j=1;j<=i;j++)
// ans+=j*(i-j+1)*(i-j+1);
// cout<<ans<<" ";
// }
int t;cin>>t;
while(t--)
{
ll n;cin>>n;n%=p;
if(n==1) {
cout<<1<<endl<<1<<endl;
continue;
}
ll ans=0;
ans=n*(n+1)%p*qpow(12,p-2)%p*n%p*(n+1)%p*(2*n+1)%p;
// cout<<ans<<endl;
// ll ans1=(n-1)*(n+2)%p*qpow(8,p-2)%p*n%p*n%p*(n+1)%p*(n+1)%p;
ll ans1=(n-1)*(n+2)%p*qpow(24,p-2)%p*(n+1)%p*(n+1)%p*((((n+1)*(n+1)%p-1)%p+p)%p)%p;
ll ans2=(n-1)*(n+2)%p*qpow(12,p-2)%p*(((n*(n+1)%p*(2*n+1)%p+3*n*(n+1)%p-12)%p+p)%p)%p;
ans2=((ans2+ans)%p+p)%p;
ans=((ans+ans1)%p+p)%p;
cout<<ans2<<endl;
ans=n*n%p*n%p*(n+1)%p*qpow(12,p-2)%p*n%p*(n+1)%p*(2*n+1)%p;
cout<<(ans+p)%p<<endl;
}
return 0;
}
这篇博客讨论了两个数学问题,第一个涉及在二维平面上找到一组点,使得无论如何二染色,总存在一个超平面将不同颜色的点分开;第二个问题是关于在三维空间中构建特定形状的立方体结构,同时计算最小和最大成本。博主通过递归和记忆化搜索的方法分别解决了这两个问题,并给出了详细的代码实现。





399

被折叠的 条评论
为什么被折叠?



