场中只过了一题A,B题发现时题意理解错了
A题选出比它大的数排序取平均值即可
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n, tmp;
double x;
scanf("%d%lf", &n, &x);
vector<int> v;
for(int i = 1; i <= n; i++) {
scanf("%d", &tmp);
if(tmp > x) v.push_back(tmp);
}
sort(v.begin(), v.end());
for(int val : v)
x = (x + val) / 2.0;
printf("%.3f\n", x);
}
B题用两个都女装的概率除以第一天女装的概率即可
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if(b == 0) return a;
else return gcd(b, a % b);
}
int main()
{
ll n, m, x, y, t;
while(~scanf("%lld%lld%lld%lld%lld", &n, &m, &x, &y, &t)) {
ll top = m * x * (m - 1) * (x - 1) + n * y * (n - 1) * (y - 1);
ll btm = (m * x + n * y) * (n - 1) * (m - 1);
if(t == 0) {
if(top == 0) printf("0.000\n");
else if(top == btm) printf("1.000\n");
else printf("%.3f\n", top * 1.0 / btm);
}
else {
if(top == btm) printf("1/1\n");
else if(top == 0) printf("0/1\n");
else {
ll pri = gcd(btm, top);
printf("%lld/%lld\n", top / pri, btm / pri);
}
}
}
}
D题先求出初始状态的逆序对数,然后枚举向后移动的珠子,移动后逆序对数=原逆序对-小于该数的数目+大于该数的数目
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
const int mod = 1000000007;
const int maxn = 200000 + 3;
vector<long long> v;
long long a[maxn];
int Ta[maxn << 1], n, cnt[maxn];
int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }
void add(int x) {
for(int i = x; i <= maxn; i += (i & -i))
Ta[i]++;
}
int get(int x) {
int sum = 0;
while(x) {
sum += Ta[x];
x -= (x & -x);
}
return sum;
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
v.push_back(a[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
long long lv = 0;
long long ans = 0;
for(int i = 1; i <= n; i++) {
int pos = getid(a[i]);
add(pos);
lv = (lv + i - get(pos)) % mod;
}
ans = lv;
for(int i = 1; i < n; i++) {
int pos = getid(a[i]);
int low = get(pos - 1);
int ab = n - get(pos);
lv = (lv - low + ab) % mod;
lv = (lv + mod) % mod; //可能出现负数!
ans = ans * lv % mod;
}
printf("%lld\n", ans);
}