标签:temp 质因数分解 方程组 names etc https \n har --
以下几乎全部抄的题解(方便自己复习)
因为这些我见都没见过(_(:з」∠)_蒟蒻瑟瑟发抖
请你找出M个和为N的正整数,他们的乘积要尽可能的大。 输出字典序最小的一种方案。
扔代码
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main ()
{
read(n);read(m);
int tot = n / m;
for (int i=1;i<=m;i++)
{
if(i<m-(n-tot*m)+1)
{
printf("%d ",tot);
} else printf("%d ",tot+1);
} return 0;
}
一个数有且只能分解为一组质数的乘积
扔代码
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int k;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
read(k);
for (int i=2;i<=k;i++)
{
if(k%i == 0)
{
printf("%d\n",k/i);
return 0;
}
} return 0;
}
LuoGu P3717 [AHOI2017初中组]cover
圆覆盖问题..大概就是公式求圆覆盖(两点间的距离公式然后直到半径好像也能求)
扔代码
//#define fre yes
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 2005;
int Map[maxn][maxn];
int n,m,r,ans;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = - 1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
void kis(int x,int y,int z)
{
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
if(pow(i-x,2)+pow(j-y,2) <= pow(r,2))
{
Map[i][j] = 1;
} }
}
}
int main ()
{
read(n);read(m);read(r);
for (int i=1;i<=m;i++)
{
int x,y;
read(x);read(y);
Map[x][y] = 1;
kis(x,y,r);
}
for(int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
if(Map[i][j] == 1)
{
ans++;
}
}
} printf("%d\n",ans);
return 0;
}
给定一个集合s(集合元素数量<=30),求出此集合所有子集元素之和
样例
输入 2 3 输出 10
解释:
[] [2] [3] [2 3] 2+3+2+3=10
扔代码
//#define fre yes
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 35;
int arr[maxn];
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main ()
{
int k = 1;
while(cin >> arr[k]) { k++; }
long long s = 0;
for (int i=1;i<=k;i++)
{
s += arr[i];
} s *= pow(2, k-2);
printf("%lld\n",s);
return 0;
}
相亲数:两个数中任意一个的所有因子(除本身外)之和等于另外一个数
扔代码
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int pr[maxn];
int S;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
void cur()
{
// O(n^2)
// for(int i=1;i<=100000;i++)
// {
// for(int j=1;j<i;j++)
// {
// if(i%j==0)
// {
// pr[i]+=j;
// }
// }
// }
//O(n sqrt(n))
int j;
for (int i=1;i<=100000;i++)
{
for (j=1;j*j<=i;j++)
{
if(i%j==0)
{
pr[i] += j;
pr[i] += i/j;
}
} j--;
if(j*j == i) pr[i] -= j;
pr[i] -= i;
}
//O(n log(log(n)))
// for(int i=1;i<=20000;i++)
// for(int j=i;i*j<=20000;j++)
// pr[i*j]+=i;
}
int main()
{
read(S);
cur();
for (int i=S;;i++)
{
if(pr[pr[i]] == i&&pr[i]!=i)
{
printf("%d %d",i,pr[i]);
return 0;
}
} return 0;
}
LuoGu https://www.luogu.org/problemnew/show/P1548
有一个棋盘 给你n m 找有多少个正方形和长方形
扔代码
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int ans1,ans2;
int n,m;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main ()
{
read(n);read(m);
ans2 = ((m+1)*(n+1)*m*n)/4;
for(int i=n,j=m;j>=1&&i>=1;j--,i--) {
ans1 += i*j;
} printf("%d %d\n",ans1,ans2-ans1);
return 0;
}
凸多边形找对角线交点个数
扔代码
//#define fre yes
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
unsigned long long n;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
read(n);
n = (n*(n-1)/2*(n-2)/3*(n-3)/4);
printf("%lld\n",n);
return 0;
}
利用 a^a=0
//#define fre yes
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,ans;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1 ; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
read(n);
for (int i=1;i<=n;i++)
{
int x;
read(x);
ans = (ans ^ x);
} printf("%d\n",ans);
return 0;
}
C++的32位无符号整形(话说有这个吗 Orz)
左移16位,就是低位转到高位;右移16位,就是高位转到低位;两者相加,就是新数
扔代码
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
scanf("%u", &n);
printf("%u\n", (n >> 16) + (n << 16));
return 0;
}
设首项为L,末项为R,那么sum(L,R)=(L+R)(R-L+1)/2=M
即(L+R)(R-L+1)=2M
可以把2M分解成两个数之积,假设分成了两个数K1,K2,且K1<K2时,
可以列一个二元一次方程组
R-L+1=K1
L+R=K2 解得L=(K2-K1+1)/2, R=(K1+K2-1)/2
当K1,K2一奇一偶时,L,R才有自然数解.
不过有一种特殊情况,就是L=R的情况,这种情况是不允许的
即(K2-K1+1)/2≠(K1+K2-1)/2,解得K1≠1
扔代码
//#define fre yes
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main(){
read(n);
for(int i=sqrt(2*n);i>1;i--)
{
if(2*n%i==0 && (i+2*n/i)%2)
{
int j=2*n/i;
printf("%d %d\n",(j-i+1)/2,(i+j-1)/2);
}
} return 0;
}
读了半天题都没读懂..但是题解写的的确是结论
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,k,h;
long long ans = 1;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
read(n);read(k);read(h);
if(k > n)
{
puts("0");
return 0;
}
for (int i=1;i<=h;i++)
{
int x;
read(x);
for(int j=1;j<=x;j++)
ans *= j;
} long long ans_g = 1;
for (int i=n;i>=n-k+1;i--) ans_g *= i * i;
printf("%lld\n",ans_g/ans);
return 0;
}
把大三角形的每条边n等分,将对应的等分点连接起来
//#define fre yes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long ans,n;
int k;
template<typename T>inline void read(T&x)
{
x = 0;char c;int lenp = 1;
do { c = getchar();if(c == ‘-‘) lenp = -1; } while(!isdigit(c));
do { x = x * 10 + c - ‘0‘;c = getchar(); } while(isdigit(c));
x *= lenp;
}
int main()
{
read(k);
while(k--)
{
ans = 0;
read(n);
for (long long i=0;n-i!=0;i++)
ans += (n-i) * (n-i+1);
for (long long i=0;n-i>=2;i+=2)
ans += (n-i) * (n-i-1);
ans /= 2;
printf("%lld\n",ans);
} return 0;
}
标签:temp 质因数分解 方程组 names etc https \n har --
原文地址:https://www.cnblogs.com/Steinway/p/9206913.html