• GAME (HDU)(博弈论)


    Alice and Bob are playing a game. They take turns and Alice moves first. There is a set of positive integers. In one's turn, he or she can choose a number (suppose xx) in the set, and choose a positive integer kk (kk does not need to be in the set), and replace xx with x-(10^k-1)x−(10k−1). For example, you can make a number xx in the set become x-9x−9 or x-99x−99 or x-999x−999 or x-999\cdotsx−999⋯. After that the set must still be a set of positive integers. That is to say:


    * The number must still be positive: x-(10^k-1) > 0x−(10k−1)>0.
    * A set can not have duplicate elements: x-(10^k-1)x−(10k−1) can not be equal to any other numbers in the set.

    They take turns and Alice moves first. The one who can't move loses the game. Now the question is that who will win the game if they play optimally.

    题意:a和b在玩游戏,给你一组正整数,每次可以减9,99,999...,但是要满足两个条件:1.减完之后必须是正整数,2.没有重复的元素

    a先移动,不能动的人输,每个人最优,求谁赢

    思路:-99,999等等都是9的倍数,最小减的数是9,那么我们就算最多能减多少次9,而且应该先对原数组排序之后再算每个数最多能减多少个9是最优解,

    那么我们就先对数组排序再对原数组求最多能减几次9

    还有一个问题是不能有重复的数,那我们先算能减的最多的数,然后我们再减去重复的操作数

    那么我们对每个数来说,%9余数是0的我们最终的数应该是9 18 27...也就是1*9 2*9 3*9,那么多算的不数就是1 2 3...假设个数为n那么重复的操作数就是n*(n+1)/2

    %9!=0的时候:假如余数是op,那我们就变到op+9*0 ,op+9*1,op+9*2...,那么操作数就是 0 1 2 ...,假设有n个余数是op的数,那么重复的操作次数就是n*(n-1)/2

    然后用总操作数减去重复的操作数就是最后的操作数了,是单数的话A赢,双数的话是B赢
     

    1. /*
    2. .----------------. .----------------. .----------------. .----------------.
    3. | .--------------. || .--------------. || .--------------. || .--------------. |
    4. | | ________ | || | _________ | || | ____ ____ | || | ____ | |
    5. | | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
    6. | | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
    7. | | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
    8. | | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
    9. | | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
    10. | | | || | | || | | || | | |
    11. | '--------------' || '--------------' || '--------------' || '--------------' |
    12. '----------------' '----------------' '----------------' '----------------'
    13. */
    14. #include
    15. #include
    16. #include
    17. #include
    18. #include
    19. #include
    20. #include
    21. #include
    22. #include
    23. #include
    24. #define int long long
    25. #define lowbit(x) x&(-x)
    26. #define PI 3.1415926535
    27. #define endl "\n"
    28. using namespace std;
    29. typedef long long ll;
    30. typedef pair<int,int> pii;
    31. int gcd(int a,int b){
    32. return b>0 ? gcd(b,a%b):a;
    33. }
    34. /*
    35. int dx[8]={-2,-2,-1,1,2,2,-1,1};
    36. int dy[8]={-1,1,2,2,1,-1,-2,-2};
    37. int dx[4]={0,-1,0,1};
    38. int dy[4]={-1,0,1,0};
    39. int dx[8]={-1,1,0,0,-1,-1,1,1};
    40. int dy[8]={0,0,-1,1,-1,1,-1,1};
    41. */
    42. //int e[N],ne[N],h[N],idx,w[N];
    43. /*void add(int a,int b,int c){
    44. e[idx]=b;
    45. w[idx]=c;
    46. ne[idx]=h[a];
    47. h[a]=idx++;
    48. }
    49. */
    50. const int N=2e5+10;
    51. int n;
    52. int a[N],b[N],c[N],book[N];
    53. signed main(){
    54. ios::sync_with_stdio(false);
    55. cin.tie() ,cout.tie() ;
    56. while(cin>>n){
    57. for(int i=0;i<=9;i++){
    58. book[i]=0;
    59. }
    60. for(int i=1;i<=n;i++){
    61. cin>>a[i];
    62. }
    63. sort(a+1,a+1+n);
    64. int ans=0;
    65. for(int i=1;i<=n;i++){
    66. b[i]=a[i]/9;
    67. c[i]=a[i]%9;
    68. ans+=b[i];
    69. book[c[i]]++;
    70. }
    71. for(int i=0;i<=8;i++){
    72. int k;
    73. if(i==0){
    74. k=book[i]*(book[i]+1)/2;
    75. }else k=book[i]*(book[i]-1)/2;
    76. ans-=k;
    77. }
    78. if(ans&1){
    79. cout<<"A"<
    80. }else cout<<"B"<
    81. }
    82. }

  • 相关阅读:
    ArrayList的线程安全类CopyOnWriteArrayList
    java计算机毕业设计医药垃圾分类管理系统源程序+mysql+系统+lw文档+远程调试
    【网站架构】10年数据库设计浓缩的绝技,实打实的设计步骤与规范
    SparkCore系列-8、RDD 读写外部数据源
    springcloud和分布式微服务学习笔记
    mysql索引性能分析(sql执行频率、慢日志分析、sql效率分析工具 profile、explain)
    MySQL 开启 binlog 日志
    后台管理系统SQL注入漏洞
    计算机网络体系结构图解
    mySQL—基础SQL语句
  • 原文地址:https://blog.csdn.net/qq_61903556/article/details/126922317