== 蓝桥杯B组(java 或者C)==
填空题
前两道填空题就不说了
这道题大多数人应该都是卡到了精度问题 double比较大小小于一定的精度我们就认为已经相等了直接上代码
#include <iostream>
#include <cstring>
#include <algorithm>
#include "cmath"
using namespace std;
typedef pair<double, double> PII;
PII l[200000];
int main(){
int n = 0;
for (int x1 = 0; x1 < 20; x1 ++ )
for (int y1 = 0; y1 < 21; y1 ++ )
for (int x2 = 0; x2 < 20; x2 ++ )
for (int y2 = 0; y2 < 21; y2 ++ )
if (x1 != x2) //去掉斜率不存在的情况
{
double k = (double)(y2 - y1) / (x2 - x1);
double b = y1 - k * x1;
l[n ++ ] = {
k, b};
}
sort (l, l + n);
int res = 1;
for (int i = 1; i < n; i ++){
if(fabs(l[i].first - l[i - 1].first) > 1e-8 || fabs(l[i].second - l[i - 1].second) > 1e-8)
res ++;
}
cout << res + 20 <<endl;
答案 :40257
}
这一道题考察的就是大数的公约数
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
int main()
{
LL n;
cin >> n;
vector<LL> d;
for (LL i = 1; i * i <= n; i ++ )
if