2020牛客寒假算法基础集训营2
2020牛客寒假算法基础集训营2
C
/*************************************************************************
> File Name: c.cpp
> Author:
> Mail:
> Created Time: 五 2/ 7 17:38:27 2020
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2005;
ll n,p[N],f[N][N];
int main(int argc, char *argv[]) {
SIS;
int n;
cin >> n;
for(int i = 1;i <= n;i++)cin >> p[i];
for(int i = f[0][0] = 1;i <= n; i++){
f[i][0] = f[i - 1][0] * (mod + 1 - p[i]) % mod;
for(int j = 1; j <= i; j++){
f[i][j] = (f[i - 1][j] * (mod + 1 - p[i]) + f[i - 1][j - 1] * p[i]) % mod;
}
}
for(int i = 0;i <= n;i++){
cout << f[n][i] << " ";
}
return 0;
}
D
/*************************************************************************
> File Name: d.cpp
> Author:
> Mail:
> Created Time: 五 2/ 7 18:00:34 2020
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 505;
ll ans;
ll x[N],y[N];
bool check(int i, int j, int k) {
return ((x[j] - x[i]) * (x[k] - x[i])
+ (y[j] - y[i]) * (y[k] - y[i]) < 0)
&& ((x[j] - x[i]) * (y[k] - y[i])
- (x[k] - x[i]) * (y[j] - y[i]) != 0);
}
int main(int argc, char *argv[]) {
SIS;
int n;
cin >> n;
for(int i = 1;i <= n; i++)cin >>x[i] >> y[i];
for(int i = 1;i <= n;i++){
for(int j = i + 1;j <= n;j ++){
for(int k = j + 1;k <= n; k++){
if(check(j,i,k) || check(k,i,j) || check(i,j,k))++ans;
}
}
}
cout << ans << endl;
return 0;
}
E
解释一下,平方后得到
\[i + j + 2\sqrt(i*j) == k \]只有i , j 必然为整数时候才会有解 且是完全平方数
例如n == 4
ans == 4
如下4种情况
(1,1,)
(4,1,)
(1.4,)
(2,2,)
/*************************************************************************
> File Name: e.cpp
> Author:
> Mail:
> Created Time: 五 2/ 7 18:13:30 2020
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
int main(int argc, char *argv[]) {
SIS;
int ans = 0;
int n;
cin >> n;
for(int i = 1;i * i <= n; i++){
for(int j = 1;j <= i ;j++){
if(i * i % j == 0){
ans += 2;
}
}
ans -= 1;
}
cout << ans << endl;
return 0;
}
F
只需要比较a1 + b1 < a2 + b2;
从最大的依次分配即可
/*************************************************************************
> File Name: f.cpp
> Author:
> Mail:
> Created Time: 五 2/ 7 19:27:09 2020
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 2e5 + 5;
vector<int> sa;
vector<int> sb;
struct Node{
int a,b,id;
bool operator < (const Node &tmp) const{
return a + b > tmp.a + tmp.b;
}
}a[N];
int main(int argc, char *argv[]) {
SIS;
int n;
cin >> n;
for(int i = 1;i <= n;i++)cin >> a[i].a;
for(int i = 1;i <= n;i++)cin >> a[i].b,a[i].id = i;
sort(a + 1,a + 1 + n);
for(int i = 1;i <= n; i++){
((i & 1) ? sa : sb).push_back(a[i].id);
}
for (auto x : sa) printf("%d ", x);
puts("");
for (auto x : sb) printf("%d ", x);
return 0;
}

浙公网安备 33010602011771号