当前位置:网站首页>【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.
边栏推荐
- C语言-函数
- ML.NET related resources
- C语言”三子棋“升级版(模式选择+AI下棋)
- 2020微信小程序反编译教程(小程序反编译源码能用吗)
- 01 Encounter typescript, build environment
- 对话庄表伟:开源第一课
- R language moves time series data forward or backward (custom lag or lead period): use the lag function in the dplyr package to move the time series data forward by one day (set the parameter n to a p
- 更新数据表update
- 多主复制的适用场景(1)-多IDC
- 长得很怪的箱图
猜你喜欢
随机推荐
浏览器自带的拾色器
Delete table data or clear table
ML.NET related resources
【MySQL】Mysql范式及外键作用
ASP.NET Core 产生连续 Guid
mongo进入报错
多主复制的适用场景(2)-需离线操作的客户端和协作编辑
Getting Started with TextBlock Control Basic Tools Usage, Get Started
小程序:matlab解微分方程「建议收藏」
gerrit中如何切换远程服务器
软件实现AT命令操作过程
苹果官网样式调整 结账时产品图片“巨大化”
删除 状态良好(恢复分区)的磁盘
C language - function
WPF project - basic usage of controls entry, you must know XAML
radiobutton的使用
「秋招系列」MySQL面试核心25问(附答案)
The principle of hough transform detection of straight lines (opencv hough straight line detection)
hough变换检测直线原理(opencv霍夫直线检测)
第05章 存储引擎【1.MySQL架构篇】【MySQL高级】








