当前位置:网站首页>CF 7月25日-7月31日做题记录
CF 7月25日-7月31日做题记录
2022-07-28 02:58:00 【nth2000】
Color the Picture( GOOD)
题意: 给定二维网格矩阵。可以使用 k k k种颜色给每个网格涂色,其中第i种颜色至多可涂 a i a_i ai个网格。问是否存在一种方法使得每个格点上下左右四个格点至少有三个格点与其自身颜色完全一致。(这里的上下左右假设是环状的上下左右即假设矩阵上下相连左右相连)
思路:由于有对称性所以随机选一格点涂上任意一种颜色,然后随机选其邻居三个格点涂上与其自身同样的颜色。然后不断试探可知要想达成目标必须每种颜色能图满涂上2列或2行。
#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)
题意:给定数组a和一整数q。从前往后遍历数组a,设当前遍历到a[i],可以进行下列操作之一:
- count++。如果a[i]>q则q- -否则什么都不做.
- count不变
求使得count最大时对应count++的i集合。
数据范围:
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
题解:
如何分析最优解所满足的性质减小搜索空间呢?
找一个解假定他是最优解并看他第一个使得q减少的点(假定为点 a q a_q aq),在此点之后若有跳过的点我们看第一个跳过的点(假设为点 a p a_p ap),实际上我们跳过 a q a_q aq转而去不跳过 a p a_p ap得到的解肯定必原来假定的最优解更优。重复执行上述步骤容易看出最优解必须满足的性质是有某个点i,i到n每个下标均要count++,i之前下标是否count++仅是 a j ≤ q a_j \leq q aj≤q对应的下标j.由于i-n全部都要count++显然i越小则可能跳过的点越少即可能参与的比赛越多。我们二分查找这样的最小的i即可。
#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的智商是否能够维持住接下来的所有
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;
}
边栏推荐
- Exness: Japanese prices rose and incomes fell, with the pound / yen breaking 165
- 工程地质实习-工程地质 题集
- What if the word selection box of win11 input method is missing?
- C # set TextBox control not editable
- SSM integration (integrated configuration)
- GNU 通用公共许可证 v2.0 GNU GENERAL PUBLIC LICENSE
- 【R语言】环境指定删除 rm函数
- RBD块存储设备的扩容以及缩容操作(六)
- 如何使用JDBC操作数据库
- 20条心灵鸡汤唯美句子,句句温情暖心!
猜你喜欢

max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType

C#实现弹出一个对话框的同时,后面的form不可用

静态博客搭建工具汇总

Uniapp - make phone calls and send text messages

《工程电磁场导论》课后习题附答案

When a dialog box pops up, the following form is not available

Leaf recognition, color feature extraction, defect detection, etc

Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
![[download file] uniapp develops small programs, downloads files and saves them locally](/img/0f/4963178e44f58ad6e3097844bb6ffd.png)
[download file] uniapp develops small programs, downloads files and saves them locally

What if the word selection box of win11 input method is missing?
随机推荐
53. Maximum Subarray最大子数组和
Embedded sharing collection 22
PCB丝印如何摆?请查收这份手册!
Original title of Blue Bridge Cup
Softek Barcode Reader 9.1.5
【ACwing 1064 小国王】状压dp
Review basic knowledge points of engineering electromagnetic field
How to reinstall win11 system with one click
ELS timer
On weight decay and discarding method
mysql存储过程 使用游标实现两张表数据同步数据
对象数组转成strin再进行,隔开的字符串,包括赛选某个字段的子,或者求和,
STM32之IO模拟串口篇
Industry insight | is speech recognition really beyond human ears?
IronOCR for .NET 2022.8
Exness: Japanese prices rose and incomes fell, with the pound / yen breaking 165
RBD块存储设备的扩容以及缩容操作(六)
QT topic 1: implementing a simple calculator
max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType
【下载文件】uniapp开发小程序,下载文件并保存到本地