今日SGU 5.20
SGU 404
题意:。。
收获:取模
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e2+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main(){
string s[maxn];
int n,m;
cin>>n>>m;
rep(i,,m+) cin>>s[i];
cout<<s[n%m==?m:n%m];
return ;
}
SGU 404
题意:给你n个人,每个人都有si和bi,两个人会打架(si>=sj&&bi<=bj || si<=sj&&bi>=bj),然后让你邀请最多的人数
里面的所有人都不能打架
收获:反过来想,就是两个人能同时出现的就是其中一个人的s和b都严格大于另一个人的s和b,那我们排完序之后就是
一个lis的问题了
下面是一个我wa了很久的代码,
反例:
5
1 1
2 9
3 4
5 5
1 1
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e5+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
struct P{
int s,b,id;
bool operator <(const P& c) const{
if(s==c.s) return b>c.b;
return s<c.s;
}
}p[maxn];
int g[maxn],pre[maxn];
void init(){
mt(g,);mt(pre,-);g[] = -;
}
void output(int x){
if(pre[x]==-){
printf("%d",p[x].id);
return;
}
output(pre[x]);
printf(" %d",p[x].id);
}
int main(){
init();
scanf("%d",&n);
rep(i,,n+) scanf("%d%d",&p[i].s,&p[i].b),p[i].id = i;
sort(p+,p+n+);
int ans = ;
rep(i,,n+){
int l = ,r = ans,pos = -;
while(l <= r){ //在前面找出找到第一个大于等于当前的b的点
int mid = (l + r) >> ;
if(p[i].b > p[g[mid]].b) l = mid + ;
else pos = mid,r = mid - ;
}
if(pos == -) ans++,pos = ans;
pre[i] = g[pos - ];
if(p[i].s <= p[g[pos]].s || g[pos] == ) g[pos] = i;
}
printf("%d\n",ans);
output(g[ans]);
return ;
}
因为s已经是递增的了,那么后面的s肯定是大于等于前面的了,那我们只要让每个s对应的b最小,这样后面的才更容易拼起来
AC代码:
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e5+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
struct P{
int s,b,id;
bool operator <(const P& c) const{
if(s==c.s) return b>c.b;
return s<c.s;
}
}p[maxn];
int g[maxn],pre[maxn];
void init(){
mt(g,);mt(pre,-);g[] = -;
}
void output(int x){
if(pre[x]==-){
printf("%d",p[x].id);
return;
}
output(pre[x]);
printf(" %d",p[x].id);
}
int main(){
init();
scanf("%d",&n);
rep(i,,n+) scanf("%d%d",&p[i].s,&p[i].b),p[i].id = i;
sort(p+,p+n+);
int ans = ;
rep(i,,n+){
int l = , r = ans, pos = -;
while(l <= r){ //在前面找出找到第一个大于等于当前的b的点
int mid = (l + r) >> ;
if(p[i].b > p[g[mid]].b) l = mid + ;
else pos = mid,r = mid - ;
}
if(pos==-) ans++, pos = ans;
pre[i] = g[pos - ];
if(p[i].b < p[g[pos]].b || g[pos] == ) g[pos] = i;
}
printf("%d\n",ans);
output(g[ans]);
return ;
}
今日SGU 5.20的更多相关文章
- 今日SGU 6.6
sgu 177 题意:给你一个一开始全是白色的正方形,边长为n,然后问你经过几次染色之后,最后的矩形里面 还剩多少个白色的块 收获:矩形切割,我们可以这么做,离散处理,对于每次染黑的操作,看看后面有没 ...
- 今日SGU 6.5
sgu 160 题意:给你n个数字 数字范围 1 到 m 问你从中取出任意数量的数字使得这些数字的积取模m最大 收获:dp,记录dp的路径 #include<bits/stdc++.h> ...
- 今日SGU 5.30
SGU 190 题意:给你个n*n的矩形,然后上面有几个点不能放东西,然后问你能不能用1*2的矩形,把能放 东西的地方放满 收获:一开始想的是,dfs,然后感觉这样的话,代码很长,而且很容易超时, 看 ...
- 今日SGU 5.29
sgu 299 题意:给你n个线段,然后问你能不能选出其中三个组成一个三角形,数字很大 收获:另一个大整数模板 那么考虑下为什么如果连续三个不可以的话,一定是不存在呢? 连续上个不合法的话,一定是 a ...
- 今日SGU 5.28
SGU 121 题意:给你一张图,问你每个顶点必须有黑白两条边(如果它的边数>=2),问你怎么染色,不行就输出no 收获:你会发现不行的情况只有一个单纯的奇数环的时候,反之我们交替染色即可 #i ...
- 今日SGU 5.27
SGU 122 题意:给你n个人,每个人有大于 N / 2(向上取整)的朋友,问你1这个人有一个书,每个人都想看,只能从朋友之间传递,然后最后回到了1这个人,问你 是否有解,然后有解输出路径 收获:哈 ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- 今日SGU 5.25
SGU 194 题意:无源汇有上下界的最大流 收获:https://wenku.baidu.com/view/0f3b691c59eef8c75fbfb35c.html #include<bit ...
- 今日SGU 5.23
SGU 223 题意:给你n*n的矩形,放k个国王,每个国王不能放在别的国王的8连边上,问你有多少种方法 收获:状态DP,因为每行的放置只会影响下一行,然我们就枚举每行的状态和对应的下一行的状态,当两 ...
随机推荐
- iOS_青花瓷Charles抓包
使用青花瓷Charles抓取手机端的网络请求: 第一步,下载安装并打开Charles watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5l ...
- log_archive_min_succeed_dest
博客上.看了一大神的文章:http://blog.csdn.net/msdnchina/article/details/45141427 我表示有疑问:归档日志路径爆满,那么对于开启归档模式的数据库, ...
- hdu_1394,线段树求逆序数
http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #include< ...
- 基于UDP的DDos反射放大攻击
转自:https://www.us-cert.gov/ncas/alerts/TA14-017A Protocol Bandwidth Amplification Factor DNS 28 to 5 ...
- poj--2083--Fractal(dfs)
Fractal Time Limit: 1000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Eval函数知识总结
说道Json,我们先来聊聊eval 一.eval是什么?(解析器) eval是一个函数,看本质function eval() { [native code] } 二.怎样使用eval? 语法:str ...
- 搭建Mysql双机热备 (主从同步)
准备两台centos7主机:10.0.18.132 master 10.0.18.136 slave 先把selinux关闭,iptables关闭 或者添加端口 132 master安装好Mysq ...
- jzoj4196 二分图计数 解题报告(容斥原理)
Description
- 解决夸dll返回dynamic无法访问
public static class DynamicFactory { //创建线程安全(对象不会再同一时刻被多个线程访问)的字典对象 private static ConcurrentDictio ...
- poj2104 K-th Number(划分树)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 66068 Accepted: 23273 Ca ...