当前位置:网站首页>【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.
边栏推荐
- 更新数据表update
- T - sne + data visualization parts of the network parameters
- .NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world
- Grafana安装后web打开报错
- 2020微信小程序反编译教程(小程序反编译源码能用吗)
- 6-22漏洞利用-postgresql数据库密码破解
- C程序是如何跑起来的01 —— 普通可执行文件的构成
- .NET 20周年专访 - 张善友:.NET 技术是如何赋能并改变世界的
- Emmet 语法
- 01 Encounter typescript, build environment
猜你喜欢
第05章 存储引擎【1.MySQL架构篇】【MySQL高级】
mongo enters error
网银被盗?这篇文章告诉你如何安全使用网银
T - sne + data visualization parts of the network parameters
t-sne 数据可视化网络中的部分参数+
11 pinia使用
Internet banking stolen?This article tells you how to use online banking safely
苹果官网样式调整 结账时产品图片“巨大化”
Browser's built-in color picker
mysql black window ~ build database and build table
随机推荐
.NET 20周年专访 - 张善友:.NET 技术是如何赋能并改变世界的
Single-cell sequencing workflow (single-cell RNA sequencing)
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
Emmet syntax
org.apache.jasperException(could not initialize class org)
json到底是什么(c# json)
Destruction order of thread_local variables
单细胞测序流程(单细胞rna测序)
MySQL多表联合查询
Linux查看redis版本(查看mongodb版本)
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
MySQL的相关问题
What is the difference between BI software in the domestic market?
what exactly is json (c# json)
Public Key Retrieval is not allowed error solution when DBeaver connects to MySQL 8.x
苹果官网样式调整 结账时产品图片“巨大化”
The 2nd China PWA Developer Day
AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
WPF project - basic usage of controls entry, you must know XAML
第二届中国PWA开发者日