当前位置:网站首页>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;
}
边栏推荐
- 关于权重衰退和丢弃法
- 20 soul chicken soup beautiful sentences, sentence by sentence warm heart!
- How to reinstall win11 system with one click
- Contour detection based on OpenCV (3)
- The digital twin smart building visualization platform realizes the integration of enterprise and public services in the park
- 【Codeforces Round #806 (Div. 4)(A~F)】
- CAD创建组却没有组合在一起?
- When QML uses layout layout, a large number of < unknown file >: QML qquicklayoutattached: binding loop detected for property circular binding warnings appear
- What is a virtual function?
- LeetCode 第二十九天
猜你喜欢

【2022 牛客第二场J题 Link with Arithmetic Progression】三分套三分/三分极值/线性方程拟合最小二乘法

Redis内存回收

“讳疾忌医”的开源走不远

《MySQL数据库进阶实战》读后感(SQL 小虚竹)

c#——switch case语句

Redis5种数据结构解析

Exness: Japanese prices rose and incomes fell, with the pound / yen breaking 165

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

stm32F407-------FPU学习

Redis 5 kinds of data structure analysis
随机推荐
Summary of static blog building tools
LeetCode 第二十九天
“讳疾忌医”的开源走不远
【R语言】环境指定删除 rm函数
Full of dry goods, hurry in!!! Easy to master functions in C language
Shell:一键部署pxe
The test post changes jobs repeatedly, jumping and jumping, and then it disappears
Review basic knowledge points of engineering electromagnetic field
傅里叶级数
[download file] uniapp develops small programs, downloads files and saves them locally
对象数组转成strin再进行,隔开的字符串,包括赛选某个字段的子,或者求和,
动画(animation)
C # set TextBox control not editable
嵌入式数据库--SQLite
C#中关闭窗体的四种方法
Embedded database -- SQLite
My approval & signature function of conference OA project
静态博客搭建工具汇总
QT official example: Fridge Magnets example
max_pool2d(): argument ‘input‘ (position 1) must be Tensor, not NoneType