当前位置:网站首页>Two-point answer naked question (plus a little pigeonhole principle)
Two-point answer naked question (plus a little pigeonhole principle)
2022-07-30 18:15:00 【lovesickman】
New Year’s Problem (naked dichotomy)
题面翻译
题目描述
Vlad 有 n n n 个朋友,Every friend needs and only needs 1 1 1 个礼物.有 m m m gift shop,如果在第 i i i friends in stores j j j 买礼物,朋友 j j j 将获得 p i j p_{ij} pij 的快乐值.
由于时间紧迫, Vlad Only at most n − 1 n-1 n−1 Buy gifts from different stores.Please make the minimum value of happiness that each friend can get is the largest.
输入格式
第一行一个整数 t t t,表示有 t t t 组测试数据.
每组测试数据之间有一个空行.对于每组测试数据,第一行两个整数 m m m 和 n n n.接下来 m m m 行,每行 n n n 个整数,其中第 i i i 行的第 j j j 个数表示 p i j p_{ij} pij.
保证 t ≤ 1 0 4 t\leq10^4 t≤104, p i j ≤ 1 0 9 p_{ij}\leq10^9 pij≤109, n ≥ 2 n\geq2 n≥2,and in all test data n ⋅ m n\cdot m n⋅m 的和不超过 1 0 5 10^5 105.
输出格式
输出 t t t 行,Each row contains the answer for the corresponding test data,即 Vlad The maximum value of the minimum happiness value among the friends of .
样例 #1
样例输入 #1
5
2 2
1 2
3 4
4 3
1 3 1
3 1 1
1 2 2
1 1 3
2 3
5 3 4
2 5 1
4 2
7 9
8 1
9 6
10 8
2 4
6 5 2 1
7 9 7 2
样例输出 #1
3
2
4
8
2
naked dichotomy,Will not judge,That's my code levelshit
- A store is responsible for at least two items
- Each person can only buy one item!
- Everyone has to have items
Two-point answer bare question.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define x first
#define y second
#define debug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N = 1e5+10;
int n,m;
bool ck(ll x,vector<vector<int>>g){
set<int>s;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(g[j][i] >= x){
s.insert(i);
}
}
}
bool ok = 0;
for(int i=0;i<m;i++){
int cnt=0;
for(int j=0;j<n;j++){
if(g[i][j] >= x){
cnt++;
}
}
if(cnt>=2){
ok = 1;
}
}
if(!ok || (int)s.size() < n )return 0;
return 1;
}
void solve(){
cin>>m>>n;
vector<vector<int>>g(m,vector<int>(n));
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>g[i][j];
}
}
ll l = 1, r = 1e9+10;
while(l<r){
ll mid = l+r+1>>1;
if(ck(mid,g)){
l = mid;
}
else{
r = mid-1;
}
}
cout<<l<<endl;
}
int main()
{
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
Doremy’s IQ
题面翻译
题目描述
哆来咪·Suit participated n n n 场比赛. 比赛 i i i 只能在第 i i i 天进行.比赛 i i i 的难度为 a i a_i ai.最初,Doremi's IQ 为 q q q . 在第 i i i 天,Doremi will choose whether to participate in the competition i.Only if she is current IQ 大于 0 0 0 时,She can enter the game.
If Doremi chooses to be in the first i i i day to participate in the game i i i,则会发生以下情况:
- 如果 a i > q a_i>q ai>q,Doremi will feel that he is not smart enough,所以 q q q 将会减 1 1 1;
- 否则,什么都不会改变.
If she chooses not to compete,一切都不会改变.Doremi wants to participate in as many competitions as possible.Please give Doremi a solution.
输入格式
第一行包含一个正整数 t t t ( 1 ≤ t ≤ 1 0 4 1\le t\le10^4 1≤t≤104) ,表示测试数据的组数.
第二行包含两个整数 n n n 和 q q q ( 1 ≤ n ≤ 1 0 5 1\le n\le10^5 1≤n≤105, 1 ≤ q ≤ 1 0 9 1\le q\le10^9 1≤q≤109),Indicates the number of games and when Doremi started IQ.
第三行包含 n n n 个整数 a 1 , a 2 ⋯ a n a_1,a_2⋯a_n a1,a2⋯an( 1 ≤ a i ≤ 1 0 9 1\le a_i≤10^9 1≤ai≤109),Indicates the difficulty of each game.
数据保证 n n n 之和不超过 1 0 5 10^5 105.
输出格式
对于每组数据,Output a binary string s s s,If Doremi should choose to participate in the competition i i i,则 s i = 1 s_i=1 si=1,否则 s i = 0 s_i=0 si=0. 字符串中 1 1 1 The number should be as large as possible,and be hers IQ 为 0 0 0 或更低时,She shouldn't be in the game.
如果有多个解决方案,You can output either one.
样例说明
在第一个测试用例中,Doremi participated in the only competition.她的 IQ 没有下降.
在第二个测试用例中,Doremi participated in two competitions.在参加比赛 2 2 2 后,她的 IQ 下降了 1 1 1.
在第三个测试用例中,Doremi participated in the competition 1 1 1 和比赛 2 2 2.她的 IQ 在参加比赛 2 2 2 后降至 0 0 0,So she couldn't participate in the competition 3 3 3.
样例 #1
样例输入 #1
5
1 1
1
2 1
1 2
3 1
1 2 1
4 2
1 4 3 1
5 2
5 1 2 4 3
样例输出 #1
1
11
110
1110
01111
Low IQ warning,I really don't understand how to think about the solution.Duality is not analyzed.
SOLUTION_1
EDITORIAL
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define x first
#define y second
#define debug(x) cout<<#x<<"="<<x<<endl;
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo_(i,a,n) for(int i=(a);i<(n);++i)
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N = 1e5+10;
int n,m;
int a[N];
bool ck(int x){
int w = m;
fo(i,x+1,n){
if(a[i]>w)w--;
}
return w>=0;
}
bool ans[N];
void solve(){
cin>>n>>m;
fo(i,1,n){
cin>>a[i];
}
int l = 0 , r = n; // l 一定要从0开始,不然会wa
while(l<r){
int mid = l+r>>1;
if(ck(mid)){
r = mid;
}
else{
l = mid+1;
}
}
fo(i,1,n){
if(i<=l){
if(a[i]<=m){
cout<<"1";
}
else{
cout<<"0";
}
}
else{
cout<<"1";
}
}
puts("");
}
int main()
{
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
边栏推荐
- mysql刷脏的几种场景以及相关参数
- Informatics Olympiad 1915: [01NOIP Popularization Group] Greatest Common Divisor and Least Common Multiple | Luogu P1029 [NOIP2001 Popularization Group] The problem of the greatest common divisor and
- ESP8266-Arduino编程实例-BMP180气压温度传感器驱动
- SQL存储过程详解
- 【解决】关于 Unity Hub 获取许可证失败 或 无响应导致无法开发的问题
- 这玩意儿都能优化?果然是细节都在魔鬼里。
- What are the applications of X-rays?
- LayaBox---TypeScript---枚举
- 单例模式 (Singleton)
- Mongo for infrastructure
猜你喜欢
网络基础(二)-Web服务器-简介——WampServer集成服务器软件之Apache+MySQL软件安装流程 & netstat -an之检测计算机的端口是否占用
CCNA-NAT协议(理论与实验练习)
Ecplise执行C语言报错:cannot open output file xxx.exe: Permission denied
linux 安装mysql8.0 超详细教程(实战多次)
Application of time series database in the field of ship risk management
Dodging ice cream assassins?Crawling ice cream prices through crawlers
ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
基于亚马逊云科技无服务器服务快速搭建电商平台——性能篇
PLSQL Developer安装和配置
图解LeetCode——11. 盛最多水的容器(难度:中等)
随机推荐
LayaBox---TypeScript---泛型
编曲软件FL Studio中文版安装教程及切换语言教程
你好好想想,你真的需要配置中心吗?
js中的基础知识点 —— BOM
使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
ROS 环境使用第三方动态链接库(.so)文件
CMake library search function does not search LD_LIBRARY_PATH
你好,我的新名字叫“铜锁/Tongsuo”
测试.net文字转语音模块System.Speech
OSPF详解(4)
Linux-安装MySQL(详细教程)
CCNA-网络汇总 超网(CIDR) 路由最长掩码匹配
ROS 节点初始化步骤、topic/service创建及使用
今年这情况。。真心推荐专科的工程师升个本!
BI报表与数据开发
【AGC】增长服务2-应用内消息示例
ByteArrayInputStream 类源码分析
基础架构之Mongo
毕业1年从事软件测试拿下11.5k,没有给98后丢脸吧...
What is NDT equipment?