• B. Elimination of a Ring Pinely Round 1 (Div. 1 + Div. 2)


    传送门

    题目意思: 给你一个为环的序列n,这个序列有一个特殊的地方:就是如果有相邻元素相等他就会立马删除其中一个元素(第一个和最后一个相邻)。 然后你每次可以删除一个元素,问你能删除的最多的操作数是多少。

    题目思路:

    我们可以发现如果有一个元素只有一个数的话,那么可以通过以这个元素为中心不断删除n次。

    首先如果元素种类为2 的话,肯定结果就是n/2+1,

    当环中至少含有三种不同的元素 假设是a,b,c(三种),然后我们以任意一个元素为中心

    ,假设是b然后删除他周围的能删的数,直到不能删了或者有一个数存在一个

    如果是不能以b为中心去删了,那么因为至少含有三种元素,那么一定会有一个元素只有一个。、

    那么无论如果都会有存在一个元素只存在一个的情况。

    所以可以一直删直到n次

    所以就是如果元素种类大于等于3就是n,否则为n/2+1;

    1. /**
    2. *  ┏┓   ┏┓+ +
    3. * ┏┛┻━━━┛┻┓ + +
    4. * ┃       ┃
    5. * ┃   ━   ┃ ++ + + +
    6. * ████━████+
    7. * ◥██◤ ◥██◤ +
    8. * ┃   ┻   ┃
    9. * ┃       ┃ + +
    10. * ┗━┓   ┏━┛
    11. *   ┃   ┃ + + + +Code is far away from  
    12. *   ┃   ┃ + bug with the animal protecting
    13. *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
    14. *   ┃       ┣┓
    15. *   ┃        ┏┛
    16. *  ┗┓┓┏━┳┓┏┛ + + + +
    17. *    ┃┫┫ ┃┫┫
    18. *    ┗┻┛ ┗┻┛+ + + +
    19. */
    20. #include
    21. #include
    22. #include
    23. #include
    24. #include
    25. #include
    26. #include
    27. #include
    28. #include
    29. #define sc_int(x) scanf("%d", &x)
    30. #define sc_ll(x) scanf("%lld", &x)
    31. #define pr_ll(x) printf("%lld", x)
    32. #define pr_ll_n(x) printf("%lld\n", x)
    33. #define pr_int_n(x) printf("%d\n", x)
    34. #define ll long long
    35. using namespace std;
    36. const int N=1000000+100;
    37. int n ,m,h;
    38. ll s[N];
    39. int main()
    40. {
    41. int t;
    42. sc_int(t);
    43. while(t--)
    44. {
    45. map<int,int>q;
    46. cin>>n;
    47. int res=0;
    48. for(int i =1;i<=n;i++)
    49. {
    50. cin>>s[i];
    51. if(!q[s[i]]){
    52. q[s[i]]=1;
    53. res++;
    54. }
    55. }
    56. if(res>=3)cout<
    57. else cout<2+1<
    58. }
    59. return 0;
    60. }

  • 相关阅读:
    Kubernetes基础(十九)-k8s存储对象Persistent Volume Claim
    【C++】初识类和对象
    HTML—css
    读卡器串口协议
    【python】bin/dec/hex/bnr进制转换函数及fp32转十六进制
    基于JavaGUI的图书管理系统
    那些转到IT行业的人,现在怎样了?
    多线程-- 原子访问和atomic原子操作类实现原理
    面试利器!阿里内部强推的RocketMQ学习指南,不能再细了
    支持jesd204b协议高速DAC芯片AD9144-FMC-EBZ配置笔记
  • 原文地址:https://blog.csdn.net/jikelk/article/details/128054507