实际上苟蒻只会做四题。。
暴力不说了。。。
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; const int maxn = 210; char c[maxn]; int n,ans = 0,x,y; int main() { #ifdef YZY freopen("yzy.txt","r",stdin); #endif cin >> n; cin >> c; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { x = y = 0; for (int l = i; l <= j; l++) { if (c[l] == 'U') ++y; else if (c[l] == 'D') --y; else if (c[l] == 'L') --x; else ++x; } if (!x && !y) ++ans; } cout << ans; return 0; }
Catherine有n张卡片,每张卡片分别是蓝绿红的其中一种颜色每次可以执行两种操作中的一种:
1:将两张同色卡片换成一张该颜色卡
2:将两张异色卡片换成一张第三种颜色卡
问:最后剩的一张卡可能是什么颜色
所有情况都讨论一遍就好。。。
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; int b,g,r,n; char c[210]; int main() { #ifdef YZY freopen("yzy.txt","r",stdin); #endif cin >> n >> c; for (int i = 0; i < n; i++) { if (c[i] == 'B') ++b; else if (c[i] == 'G') ++g; else ++r; } if (b && g && r) { printf("BGR"); return 0; } if (!b && !g) { printf("R"); return 0; } if (!b && !r) { printf("G"); return 0; } if (!g && !r) { printf("B"); return 0; } if (!b) { if (g > 1 && r > 1) { printf("BGR"); return 0; } if (g == 1 && r == 1) { printf("B"); return 0; } if (g == 1) { printf("BG"); return 0; } else { printf("BR"); return 0; } } if (!g) { if (b > 1 && r > 1) { printf("BGR"); return 0; } if (b == 1 && r == 1) { printf("G"); return 0; } if (b == 1) { printf("BG"); return 0; } else { printf("GR"); return 0; } } if (b > 1 && g > 1) { printf("BGR"); return 0; } if (b == 1 && g == 1) { printf("R"); return 0; } if (b == 1) { printf("BR"); return 0; } else { printf("GR"); return 0; } return 0; }
好多小孩在玩建塔游戏。。。其中一队只有高度为2的积木,另一队只有高度为3的积木,他们都不喜欢自己建的塔的高度和其他小孩一样,问满足条件情况下最高的塔的高度最低是多少
对于任意i,记
a1:小于等于i的所有数中是2的倍数但不是6的倍数的数
a2:小于等于i的所有数中是3的倍数但不是6的倍数的数
a3:小于等于i的所有数中是6的倍数的数
若a1+a2+a3 >= n+m 则i是解
答案挺小的。。。
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; const int maxn = 1E6 + 10; int ar[maxn*3],n,m,tw,tr; int main() { #ifdef YZY freopen("yzy.txt","r",stdin); #endif cin >> n >> m; for (int i = 1; ; i++) { int a1 = max(n - (i/2 - i/6),0); int a2 = max(m - (i/3 - i/6),0); int a3 = i/6; if (a1 + a2 <= a3) { cout << i; return 0; } } return 0; }
题意:
Andrew and Jerry 正在玩一种游戏。。。现有一个瓶子里面装着n个球,每个球有一个编号,每次两人分别从瓶里拿出一个球,编号大的人获胜,然后将球放回。一共三局,三局两胜。Andrew总能赢得前两局,于是Jerry不乐意了,他想知道他有多大概率,使得三次编号和大于Andrew的
题解:
因为胜利是固定属于一方,所以枚举出所有胜利方式,约n^2种,每次是这里面的一种。注意到胜利方的分数能比失败方多(废话。。。)于是通过这两数只差建立数组a,记a[i]为胜利方比失败方多i分的方案数,显然,1<=i<5000,于是我们可以枚举前两局情况,得出答案
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; const int maxn = 2E3 + 10; typedef double DB; int n,num[maxn]; DB ans = 0,cur = 0,sum[3*maxn],a[3*maxn]; int main() { #ifdef YZY freopen("yzy.txt","r",stdin); #endif cin >> n; for (int i = 0; i < n; i++) scanf("%d",&num[i]); sort (num,num + n); int cur = 0; for (int i = n - 1; i; i--) for (int j = i - 1; j >= 0; j--) { cur += 1; a[num[i] - num[j]] += 1; } //cur = cur*cur*cur; for (int i = 5000; i; i--) sum[i] = a[i] + sum[i+1]; for (int i = 1; i <= 5000; i++) a[i] /= cur, sum[i] /= cur; for (int i = 1; i < 5000; i++) for (int j = 1; j < 5000; j++) if (i + j < 5000) { int x = i + j + 1; ans += sum[x]*a[i]*a[j]; } printf("%.12f",ans); return 0; }
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.
The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.
The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.
In the first line, print a single integer k — the size of the subset.
In the second line, print k integers — the elements of the subset in any order.
If there are multiple optimal subsets, print any.
4 1 2 3 12
3 1 2 12
4 1 1 2 2
3 1 1 2
2 1 2
2 1 2
In the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5 - 2 = 3.
In the second case, the optimal subset is . Note that repetition is allowed.
In the last case, any subset has the same median and mean, so all have simple skewness of 0.
题意:
从给定的n个数中选任意个数组成可重集,输出一种使得排序后其平均值-中位数最大的方案
题解:
苟蒻其实是不会做的。。。显然可以排除偶数的方案(我不知道为什么)然后,对于奇数方案,枚举中位数及个数,使得平均值最大的集合显然确定,然后这玩意是可以三分的。。。。。。。
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; const int maxn = 2E5 + 10; typedef long long LL; typedef double DB; LL num[maxn],sum[maxn]; int n,pos,cnt; DB MAX = 0; DB solve(int i,int x) { DB avg = (DB)(sum[i-1] - sum[i-1-x] + num[i] + sum[n] - sum[n-x])/(DB)(2*x + 1); if (avg - (DB)(num[i]) > MAX) { MAX = avg - (DB)(num[i]); pos = i; cnt = x; } return avg - (DB)(num[i]); } int main() { #ifdef YZY freopen("yzy.txt","r",stdin); #endif cin >> n; for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]); sort (num + 1,num + n + 1); for (int i = 1; i <= n; i++) sum[i] = num[i] + sum[i-1]; pos = 1; for (int i = 1; i <= n; i++) { int L = 0,R = min(i-1,n-i); while (R - L > 2) { int mid1 = L + (R-L)/3; int mid2 = R - (R-L)/3; if (solve(i,mid1) > solve(i,mid2)) R = mid2; else L = mid1; } solve(i,L); solve(i,R); if (R - L > 1) solve(i,L+1); } printf("%d\n",cnt*2 + 1); for (int i = pos-cnt; i <=pos; i++) printf("%d ",num[i]); for (int i = n; i > n-cnt; i--) printf("%d ",num[i]); return 0; }