当前位置:网站首页>CF question making record from July 25th to July 31st
CF question making record from July 25th to July 31st
2022-07-28 03:29:00 【nth2000】
Color the Picture( GOOD)
The question : Given a two-dimensional grid matrix . have access to k k k Color each grid with two colors , Among them the first i Colors can be painted at most a i a_i ai Grid (s) . Ask whether there is a way to make at least three of the four grid points above, below, left and right of each grid point completely consistent with its own color .( Here, the upper, lower, left and right assumptions are circular, that is, assume that the matrix is connected up and down, left and right )
Ideas : Due to the symmetry, a grid point is randomly selected and painted with any color , Then randomly choose three grid points of their neighbors and paint them with the same color as themselves . Then I kept trying to know that in order to achieve the goal, every color must be painted 2 Column or 2 That's ok .
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
bool solve(int a[],int m,int n,int k)
{
int pre = 0;
for(int i = k - 1;i>=0;i--)
{
if(a[i]/n < 2) return false;
pre += a[i]/n - 2;
if(2 * (k - i) <= m && (2 * (k - i) + pre)>=m) return true;
}
return false;
}
int main()
{
int t;
scanf("%d",&t);
for(int i = 0;i<t;i++)
{
int n,m,k; scanf("%d%d%d",&n,&m,&k);
int a[k];
for(int j=0;j<k;j++)
{
scanf("%d",&a[j]);
}
sort(a,a+k);
if(solve(a,n,m,k) || solve(a,m,n,k)) printf("YES\n"); else printf("NO\n");
}
system("pause");
return 0;
}
Doremy’s IQ(1600 GOOD)
The question : Given array a And an integer q. Traversing arrays from front to back a, Set the current traversal to a[i], You can do one of the following :
- count++. If a[i]>q be q- - Otherwise, do nothing .
- count unchanged
To make count The maximum time corresponds to count++ Of i aggregate .
Data range :
l e n ( a ) ≤ 1 e 5 , 1 e 9 ≥ a [ i ] ≥ 1 len(a) \leq 1e^5,1e^9 \geq a[i]\geq1 len(a)≤1e5,1e9≥a[i]≥1
Answer key :
How to analyze the properties of the optimal solution to reduce the search space ?
Find a solution, assume that it is the optimal solution, and see that it first makes q Reduced points ( Assume point a q a_q aq), If there is a skipped point after this point, let's look at the first skipped point ( Assume point a p a_p ap), In fact, we skip a q a_q aq Instead of skipping a p a_p ap The obtained solution must be better than the original assumed optimal solution . By repeating the above steps, it is easy to see that the optimal solution must satisfy a certain point i,i To n Each subscript must count++,i Whether the previous subscript count++ Is only a j ≤ q a_j \leq q aj≤q The corresponding subscript j. because i-n We need all of them count++ obviously i The smaller the size, the less points you may skip, that is, the more games you may participate in . Let's find the smallest one in two i that will do .
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int check(int q,int m,int n,int a[])
{
int count = 0;
for(int i = 0 ;i < m;i++) if(a[i]<q) count++;
//q Is your IQ able to maintain all the following
count += (n - m);
for(int i = m;i<n;i++)
{
if(a[i] <= q) continue;
else if(a[i] > q)
{
q--;
if(q < 0) return -1;
}
}
return count;
}
int main()
{
int t;scanf("%d",&t);
for(int i = 0;i<t;i++)
{
int n,q; scanf("%d%d",&n,&q);
int a[n];
for(int k = 0;k<n;k++) scanf("%d",&a[k]);
int l = 0,r = n;
int ans = 0;
while(l < r)
{
int m = (l + r) >> 1;
int temp = check(q,m,n,a);
if(temp != -1) r=m; else l = m + 1;
}
for(int k = 0;k<l;k++) if(a[k]<=q) printf("1"); else printf("0");
for(int k = l;k<n;k++) printf("1");
printf("\n");
}
return 0;
}
边栏推荐
- 图文并茂:JVM 内存布局详解
- ssm整合(整合配置)
- VMware virtual machine network settings
- The object array is converted to string and then separated by strings, including the competition to select the children of a field, or the sum,
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- GNU 通用公共许可证 v2.0 GNU GENERAL PUBLIC LICENSE
- max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
- Leetcode 208. implement trie (prefix tree) (2022.07.27)
- Shell编写规范和变量
- Redis持久化机制
猜你喜欢
随机推荐
如何使用JDBC操作数据库
xctf攻防世界 Web高手进阶区 unserialize3
vba批量读取sql的create文来创建表
在线问题反馈模块实战(十六):实现查详情功能
Redis基本操作
Methods of SQL server backup database
mysql存储过程 使用游标实现两张表数据同步数据
max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
Redis持久化机制
How to make the Internet access the intranet IP (used by esp8266 web pages)
Win11如何重命名音频设备
golang 获取循环嵌套结构的tag
Redis通信协议--RESP协议
20220727使用汇承科技的蓝牙模块HC-05配对手机进行蓝牙串口的演示
Robot development -- lead screw and guide rail
Embedded database -- SQLite
容器相关的概念
STM32 RT-Thread虚拟文件系统挂载操作
GNU General Public License v2.0 GNU General Public License
【R语言】环境指定删除 rm函数









