当前位置:网站首页>【7.29】Code Source - 【Arrangement】【Stone Game II】【Cow and Snacks】【Minimum Number of Spawns】【Sequence】
【7.29】Code Source - 【Arrangement】【Stone Game II】【Cow and Snacks】【Minimum Number of Spawns】【Sequence】
2022-07-31 15:49:00 【ZhgDgE】
#746. 排列
题意: T ≤ 1000 , 1 ≤ n ≤ 100 T\leq 1000,1\leq n\leq 100 T≤1000,1≤n≤100

思路:首先按照 a i a_i ai 降序排列.当 n ≥ 3 n\geq 3 n≥3 时,Worst case all the buffs go to someone a i a_i ai 的身上,Then this person's gain goes to someone else a j a_j aj (不是前面的 a i − 1 a_{i-1} ai−1)身上,这样的话会使得 a i − 1 , a i a_{i-1},a_i ai−1,ai 之间的差 a i − a i − 1 a_i-a_{i-1} ai−ai−1 最大化.If the two numbers are still non-increasing after maximization,Then the two numbers will not contradict.对于每个 i i i All can be judged.注意如果 a a a 值相同的,要按照 b b b 值升序排列,This maximizes the difference.
AC代码:http://oj.daimayuan.top/submission/309613
#738. 石子游戏 II
题意:共有 n ( 1 ≤ n ≤ 1 0 6 ) n(1\leq n\leq 10^6) n(1≤n≤106) 堆石子,其中第 i i i The heap initially contains a i ( 1 ≤ a i ≤ 1 0 9 ) a_i(1\leq a_i\leq 10^9) ai(1≤ai≤109) 个石子.They take turns doing one of the following:
Divide a pile of odd-numbered stones into two piles,Neither heap can be empty.
Combine two piles of even-numbered stones into one pile.
The person who cannot do anything will lose the game.问先手必胜或必败.
思路:First discover some properties.Operates on odd heaps,The number of odd numbers is constant,The operation will have one more even number at a time;Operates on even heaps,Even numbers will only get smaller,The operation is one less even number at a time.Then it is easy to know that the situation where the number of even heaps is even is the winning state,Because in the end even heaps will only be odd.Pay attention to the situation that the special judge can't operate at first.
AC代码:http://oj.daimayuan.top/submission/309308
#807. Cow and Snacks
题意:
有编号从 1 1 1 开始的 n n n 种小吃,每种小吃只有一份.有 m m m 个客人会来,每个客人有两种最喜欢的口味.The order in which guests arrive can be arranged at will.每个客人来到农场时,会把他喜欢的口味的小吃全部吃掉(如果有的话).如果没有他喜欢的口味,那么他就会伤心地离开.
Ask the guests how to line up,能使伤心的客人最少?输出最少的伤心的客人的数量.
思路:First let's consider the situation in which no one is sad,If the data is structured as a graph,Equivalent to the edge of these people constituted 一棵树 .If someone is sad,Then both points must fall on a tree,That is, a ring is formed,No longer a tree.Connectivity can be maintained using unions,See how many people's two points fall on a tree.
AC代码:http://oj.daimayuan.top/submission/309775
#811. 最小生成数
题意: n − 1 n - 1 n−1 个点,从 2 2 2 到 n ( 2 ≤ n ≤ 1 0 7 ) n(2\leq n\leq 10^7) n(2≤n≤107),点 a a a 与点 b b b 的边权为 lcm ( a , b ) \text{lcm}(a,b) lcm(a,b),求出 n − 1 n−1 n−1 个点的最小生成树.
思路:贪心.对于合数 x x x ,We connect it to its smallest prime factor m i n p ( x ) minp(x) minp(x) ,This costs x x x .连完之后,It is found that the composite numbers are connected to the prime numbers,We also have to make the prime numbers connected.容易知道 2 − 3 , 2 − 5 , 2 − 7 ⋯ 2-3,2-5,2-7\cdots 2−3,2−5,2−7⋯ 比 2 − 3 , 3 − 5 , 5 − 7 ⋯ 2-3,3-5,5-7\cdots 2−3,3−5,5−7⋯ 更优,So all prime numbers are connected 2 2 2 身上.
AC代码:http://oj.daimayuan.top/submission/309654
#664. 数列
题意:给定 d , p ( 1 ≤ d , p ≤ 1 0 9 ) d,p(1\leq d,p\leq 10^9) d,p(1≤d,p≤109) ,Find the number of sequences that satisfy the following properties,对 p p p 取模.
- 非空,长度任意. 1 ≤ a 1 < a 2 < ⋯ < a n − 1 < a n ≤ d 1\leq a_1 <a_2<\cdots<a_{n-1}<a_n\leq d 1≤a1<a2<⋯<an−1<an≤d .Prefix XOR sequence c c c 递增.
思路:First dig out the nature:the highest bit of the sequence 1 1 1 必须是递增的,satisfy this property.
Then the sequence length will not exceed 31 31 31 .The way I wrote it:定义 d p ( i , j ) dp(i,j) dp(i,j) 表示长度为 i i i 且第 i i i The highest bit of each element is j j j 的方案数. d p ( i , j ) = ∑ k = 0 j − 1 ( d p ( i − 1 , k ) × c o u n t ( j ) ) dp(i,j)=\sum_{k=0}^{j-1}{(dp(i-1,k)\times count(j))} dp(i,j)=∑k=0j−1(dp(i−1,k)×count(j)) , c o u n t ( j ) count(j) count(j) Indicates that the highest bit is j j j The number of numbers in the range.时间复杂度 O ( n + log 3 n ) O(n+\log ^3 n) O(n+log3n)
But the idea given by the solution is simpler.We group by the highest order,例如 d = 9 : [ 1 ] , [ 10 , 11 ] , [ 100 , 101 , 110 , 111 ] , [ 1000 , 1001 ] d=9:[1],[10,11],[100,101,110,111],[1000,1001] d=9:[1],[10,11],[100,101,110,111],[1000,1001] ,Then each group has c o u n t ( j ) + 1 count(j)+1 count(j)+1 种选择(Choose one or not),乘法原理乘起来即可.时间复杂度 O ( n ) O(n) O(n) .
AC代码:http://oj.daimayuan.top/submission/309743
Today's question is a bit watery.Brushed more than half,It will be finished in no time.
边栏推荐
- ASP.NET Core 产生连续 Guid
- i.MX6ULL驱动开发 | 33 - NXP原厂网络设备驱动浅读(LAN8720 PHY)
- 6-22漏洞利用-postgresql数据库密码破解
- Single-cell sequencing workflow (single-cell RNA sequencing)
- 为什么黑客领域几乎一片男生?
- what exactly is json (c# json)
- gerrit中如何切换远程服务器
- arm按键控制led灯闪烁(嵌入式按键实验报告)
- 【7.28】代码源 - 【Fence Painting】【合适数对(数据加强版)】
- Kubernetes原理剖析与实战应用手册,太全了
猜你喜欢
随机推荐
【MySQL】Mysql范式及外键作用
mongo enters error
多主复制的适用场景(2)-需离线操作的客户端和协作编辑
贪吃蛇项目(简单)
11 pinia使用
2020微信小程序反编译教程(小程序反编译源码能用吗)
删除表格数据或清空表格
MySQL基础篇【单行函数】
Codeforces Round #796 (Div. 2)(A-D)
[MySQL] Mysql paradigm and the role of foreign keys
Dialogue with Zhuang Biaowei: The first lesson of open source
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the grouped box plot, use the ggpar function to change the graphical parameters (caption, add, modify th
Applicable Scenarios of Multi-Master Replication (1) - Multi-IDC
Oracle dynamically registers non-1521 ports
MySQL数据库操作
基于ABP实现DDD
C程序是如何跑起来的01 —— 普通可执行文件的构成
苹果官网样式调整 结账时产品图片“巨大化”
The new BMW 3 Series is on the market, with safety and comfort
做事软件开发-法的重要性所在以及合理结论的认识









