当前位置:网站首页>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;
}
边栏推荐
- Review basic knowledge points of engineering electromagnetic field
- Comprehensive case
- Summary of concurrent programming interview questions
- [2022 Niuke multi school 2 K link with bracket sequence I] bracket linear DP
- Full of dry goods, hurry in!!! Easy to master functions in C language
- 随机森林与集成方法学习笔记
- [SAML SSO solution] Shanghai daoning brings you SAML for asp NET/SAML for ASP. Net core download, trial, tutorial
- Redis实现分布式锁
- Redis communication protocol -- resp protocol
- Shell:资源监控脚本和高负载报警
猜你喜欢

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

Brush questions every day to consolidate knowledge

Review basic knowledge points of engineering electromagnetic field

How to reinstall win11 system with one click

Softek Barcode Reader 9.1.5

Shell:一键部署pxe

SQL Server备份数据库的方法

SSM integration (integrated configuration)

Shell:资源监控脚本和高负载报警

Summary of concurrent programming interview questions
随机推荐
xctf攻防世界 Web高手进阶区 unserialize3
颜色的识别方法和探索 基于matlab
More than 50 interviews have been summarized, and notes and detailed explanations have been taken from April to June (including core test sites and 6 large factories)
线程基础
Redis 5 kinds of data structure analysis
Uniapp - make phone calls and send text messages
4、 Analysis of solid state disk storage technology (paper)
ELS displays a random square
[uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 2/100
【uni-app高级实战】手把手带你学习一个纯实战复杂项目的开发2/100
酒店vr全景展示拍摄提供更多合作和洽谈的机会
On weight decay and discarding method
[acwing 1064 little king] shaped pressure DP
vba批量读取sql的create文来创建表
C # set TextBox control not editable
QT official example: Fridge Magnets example
QFileDevice、QFile、QSaveFile、QTemporaryFile
【Codeforces Round #806 (Div. 4)(A~F)】
并发编程面试题总结
[nature of class (in Objective-C language)]