• The 2021 CCPC Weihai Onsite E. CHASE!


    Setsuna likes staying at home. No matter what happens at school, she has little interest and only wants to go home to play games. One day when she was back, she opened a rhythm game and found that her favorite event was helding.

    For each round in this event, a player has to play two different songs which are randomly chosen by system. There are totally nn songs in the system, and Setsuna is able to gain a score of aiai if she plays the ii-th song. The score of a round is the sum of scores of the two songs.

    Initially the system presents two different songs which are randomly selected with equal probability. If the player is unsatisfied with the result, he can ask the system to reselect (of course randomly). But there are only kk opportunities of reselecting in total.

    Setsuna had many questions. Firstly, she wanted to know her expected score under optimal decision. Secondly, she assumpted QQ cases, each of which was as the form of "the system selected the xx-th song and the yy-th song currently, and there were cc chances of reselecting left", and you need to answer whether she should accept the result, or decide to reselect, or both are OK if the difference of expected scores of these two choices under optimal decision is less or equal than 10−410−4.

    Input

    The first line containts three integers n,k,Qn,k,Q. (2≤n≤105, 1≤Q≤105, 0≤k≤1002≤n≤105, 1≤Q≤105, 0≤k≤100)

    The second line contains nn integers a1,⋯,ana1,⋯,an. (0≤ai≤1060≤ai≤106)

    Next QQ lines each contains three integers x,y,cx,y,c. (1≤x

    Output

    The first line contains a real number, representing the maximum expected score. The absolute difference between your answer and the standard answer should be within 10−410−4.

    For next QQ lines, if she should accept the result in the ii-th case, output "accept"; if she should reselect, output "reselect"; if both are OK, output "both".

    Example

    input

    Copy

    3 2 1
    30 40 50
    1 2 1
    

    output

    Copy

    85.555555556
    reselect

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. #define sc(x) scanf("%d",&x)
    4. #define sl(x) scanf("%lld",&x)
    5. #define ll long long
    6. #define pb push_back
    7. typedef pair<int,int>PII;
    8. const ll INF=1e18+5;
    9. const int mod=1e9+7;
    10. const int Max=1e6+5;
    11. ll n,k,q;
    12. ll a[Max];
    13. double f[Max];
    14. ll num=0;
    15. ll sum[Max];
    16. ll solve(double x){
    17. ll ret=0;
    18. for (int l = 1, r = n; l <= n; l ++){
    19. if(r <= l)
    20. r = l + 1;
    21. while(1){
    22. if(r == l + 1 || a[r - 1] + a[l] < x)
    23. break;
    24. r --;
    25. }
    26. if(a[r] + a[l] >= x){
    27. num += n - r + 1;
    28. ret += sum[n] - sum[r - 1];
    29. ret += (n - r + 1) * a[l];
    30. }
    31. }
    32. return ret;
    33. }
    34. ll C2(ll n){
    35. return n * (n - 1) / 2;
    36. }
    37. ll b[Max];
    38. int main(){
    39. sl(n);sl(k);sl(q);
    40. ll ans=0;
    41. for(int i=1;i<=n;i++) sl(a[i]),ans+=1LL * a[i] * (n-1),b[i]=a[i];
    42. f[0]=2.0 * ans / (n*(n-1));
    43. sort(a+1,a+1+n);
    44. for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    45. for(int i=1;i<=k;i++){
    46. num=0;
    47. ll ret=solve(f[i-1]);
    48. f[i]=2.0 * (f[i-1]*((n*(n-1)/2-num))+ret) / (n*(n-1));
    49. }
    50. printf("%.9lf\n",f[k]);
    51. while(q--){
    52. ll x, y, c;
    53. scanf("%lld%lld%lld", &x, &y, &c);
    54. if (c == 0) printf("accept\n");
    55. else {
    56. c --;
    57. double cursum = b[x] + b[y];
    58. if(fabs(f[c] - cursum) < 1e-4)
    59. puts("both");
    60. else if(f[c] < cursum)
    61. puts("accept");
    62. else
    63. puts("reselect");
    64. }
    65. }
    66. }

    掉坑点:

    1.一直以为题意中的left是左边,但是居然是留下,焯,卡一小时

    2.运用双指针时,需要先排序,但是忘记保留原数组了!!!!

    3.双指针求每个点贡献错误!!!

    4.long double   %Lf输出,不然报错!!!

  • 相关阅读:
    Java案例:求平方根
    停止tomcat服务器的几种方式、修改tomcat默认的端口号、第一种部署Web工程的方式、第二种部署Web工程的方式
    java学习第三天笔记-java基础概念13-idea中的第一个代码37
    期末前端web大作业:用DIV+CSS技术设计的动漫网站——火影忍者6页 带报告
    小游戏sdk对接,提高用户黏度
    【新版】软考 - 系统架构设计师(总结笔记)
    使用JPofiler工具分析OOM原因
    ruby on rails 常用时间
    【经历】跨境电商公司目前已在职近2年->丰富且珍贵
    最详细的Keycloak教程(建议收藏):Keycloak实现手机号、验证码登陆——(二)Keycloak与SpringBoot的集成
  • 原文地址:https://blog.csdn.net/weixin_53745698/article/details/126769525