LibreOJ一本通题解报告
目录
·贪心
·二分三分
解析啥的以后会有的
贪心目录
·T2种树
·练习T1
·练习T2
·练习T3
·练习T4
·练习T5
·练习T6
二分三分目录
·T3扩散
T1活动安排
/*
problem:yibentong10000
date:2019/4/21
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e3+;
struct node{
int s,f,dif;
};
node a[maxn];
int n,ans;
inline void init(){
cin>>n;
for(int i =;i <= n;i++)scanf("%d%d",&a[i].s,&a[i].f);
}
inline bool cmp(node x,node y){
return x.f < y.f;
}
int main(){
init();
sort(a+,a++n,cmp);
ans = ;
int tmp = a[].f;
for(int i = ;i <= n;i++)
if(a[i].s >= tmp){
ans++;
tmp = a[i].f;
}
cout<<ans<<endl;
return ;
}
T2种树
/*
problem:yibentong10001
date:2019.4.21
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 3e4+;
struct node{
int b,e,t;
}a[maxn];
int visit[maxn];
int n,ans,h;
inline void init(){
cin>>n;
cin>>h;
for(int i = ;i <= h;i++)
scanf("%d%d%d",&a[i].b,&a[i].e,&a[i].t);
}
inline bool cmp(node x,node y){
return x.e < y.e;
}
int main(){
init();
sort(a+,a++h,cmp);
for(int i = ;i <= h;i++){
int cnt = ;
for(int j = a[i].b;j <= a[i].e;j++)
cnt += visit[j];
if(cnt >= a[i].t)continue;
for(int j = a[i].e;j >= a[i].b;j--)
if(!visit[j]){
visit[j] = ;
cnt++;
ans++;
if(cnt == a[i].t)break;
}
}
cout<<ans<<endl;
return ;
}
T3喷水装置
/*
problem:yibentong10002
date:2019/4/21
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 25e3+;
struct node{
double head,tail;
}a[maxn];
int n,l,w,T,cnt,ans;
inline bool cmp(node x,node y){
return x.head < y.head;
}
inline void init(){
cin>>n>>l>>w;
cnt = ;
for(int i = ,r,position;i <= n;i++){
scanf("%d%d",&position,&r);
if(r <= w/)continue;
cnt++;
double tmp = r*r-w*w/4.0;
a[cnt].head = position-sqrt(tmp);
a[cnt].tail = position+sqrt(tmp);
}
}
int main(){
cin>>T;
while(T--){
init();
sort(a+,a++cnt,cmp);
ans = ;
double position = ;
bool flag = false;
while(position < l){
ans++;
double tmp = position;
for(int i = ;a[i].head <= tmp && i <= cnt;i++)
if(position < a[i].tail)
position = a[i].tail;
if(position == tmp && position < l){
puts("-1");
flag = true;
break;
}
}
if(flag == false)cout<<ans<<endl;
}
return ;
}
T4加工生产调度
/*
problem:yibentong10003
date:2019/4/30
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e3+;
struct node{
int position,Min;
}p[maxn];
int a[maxn],b[maxn],ans[maxn];
int n;
inline void init(){
cin>>n;
for(int i = ;i <= n;i++)scanf("%d",&a[i]);
for(int i = ;i <= n;i++)scanf("%d",&b[i]);
for(int i = ;i <= n;i++){
p[i].Min = min(a[i],b[i]);
p[i].position = i;
}
}
inline bool cmp(node x,node y){
return x.Min < y.Min;
}
int main(){
init();
sort(p+,p++n,cmp);
int tmph = ,tmpt = n+;
for(int i = ;i <= n;i++)
if(p[i].Min == a[p[i].position]){tmph++;ans[tmph] = p[i].position;}
else{tmpt--;ans[tmpt] = p[i].position;}
int timea = ,timeb = ;
for(int i = ;i <= n;i++){
timea += a[ans[i]];
if(timeb < timea)timeb = timea;
timeb += b[ans[i]];
}
cout<<timeb<<endl;
for(int i = ;i <= n;i++)printf("%d%c",ans[i],i == n ? '\n':' ');
return ;
}
T5智力大冲浪
/*
problem:yibentong10004
date:2019/4/30
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 5e2+;
struct node{
int x,y;
}a[maxn];
int vis[];
int flag,s;
int cmp(node a,node b){
return a.y > b.y;
}
int main(){
int m,n;
cin>>m>>n;
for(int i = ;i <= n;i++)scanf("%d",&a[i].x);
for(int i = ;i <= n;i++)scanf("%d",&a[i].y);
sort(a+,a+n+,cmp);
for(int i = ;i <= n;i++){
flag = ;
for(int j = a[i].x;j >= ;j--)
if(vis[j] == ){
flag = ;
vis[j] = ;
break;
}
if(flag == ){
for(int k = n;k >= ;k--)
if(vis[k] == ){
vis[k] = ;
break;
}
s += a[i].y;
}
}
printf("%d\n",m-s);
return ;
}
练习T1数列极差
/*
problem:yibentonglian10000
date:2019/5/5
author:Lonely.Devil
*/ #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 1e3+;
int a[maxn];
int n,Max,Min;
int main(){
cin>>n;
for(int i = ;i <= n; i++)
scanf("%d",&a[i]);
int tmp;
cin>>tmp;
sort(a+,a++n);
Min = a[n];
for(int i = ;i < n;i++)
Min = Min*a[n-i]+;
for(int i = ;i <= n;i++){
a[i+] = a[i]*a[i+]+;
for(int j = i+;j < n;j++)
if(a[j] > a[j+])
swap(a[j],a[j+]);
}
Max = a[n];
cout<<Max-Min<<endl;
return ;
}
练习T2数列分段
/*
problem:yibentonglian10001
date:2019/5/5
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
using namespace std;
int n,m,ans,now;
int main(){
cin>>n>>m;
for(int i = ,tmp;i <= n;i++){
scanf("%d",&tmp);
now += tmp;
if(now < m && i == n){
ans++;
break;
}
if(now > m){
ans++;
now = tmp;
}
if(now == m){
ans++;
now = ;
}
}
cout<<ans<<endl;
return ;
}
练习T3线段
/*
problem:yibentonglian10002
date:2019/5/5
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e6+;
struct node{
int x,y;
}a[maxn];
int n,now,ans;
inline bool cmp(node a,node b){
return a.y < b.y;
}
int main(){
cin>>n;
for(int i = ;i <= n;i++)scanf("%d%d",&a[i].x,&a[i].y);
sort(a+,a++n,cmp);
now = a[].y;
ans = ;
for(int i = ;i <= n;i++){
if(a[i].x >= now){
ans++;
now = a[i].y;
}
}
cout<<ans<<endl;
return ;
}
练习T4家庭作业
/*
problem:yibentonglian10003
date:2019/5/5
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e6+;
struct node{
int date,val;
}a[maxn];
bool visit[maxn];
bool flag;
int n,ans,s;
inline bool cmp(node a,node b){
return a.val > b.val;
}
int main(){
cin>>n;
for(int i = ;i <= n;i++)scanf("%d%d",&a[i].date,&a[i].val);
memset(visit,false,sizeof(visit));
sort(a+,a++n,cmp);
for(int i = ;i <= n;i++){
if(a[i].date <= s)continue;
flag = false;
for(int j = a[i].date;j >= ;j--)
if(visit[j] == false){
visit[j] = true;
ans += a[i].val;
flag = true;
break;
}
if(flag == false)s = a[i].date;
}
cout<<ans<<endl;
return ;
}
练习T5钓鱼
/*
problem:yibentonglian10004
date:2019/5/5
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn = 1e2+;
int a[maxn],d[maxn],t[maxn],fish[maxn];
int n,ans,h,sum,Max,position;
int main(){
cin>>n>>h;
h *= ;
for(int i = ;i <= n;i++)scanf("%d",&a[i]);
for(int i = ;i <= n;i++)scanf("%d",&d[i]);
for(int i = ,tmp;i < n;i++)scanf("%d",&tmp),t[i] = t[i-]+tmp;
for(int i = ;i <= n;i++){
for(int j = ;j <= i;j++)fish[j] = a[j];
int time = h - t[i-];
sum = ;
for(int j = ;j <= time;j++){
Max = ;
for(int k = ;k <= i;k++)
if(fish[k] > Max)Max = fish[k],position = k;
if(Max == )break;
fish[position] -= d[position];
sum += Max;
}
ans = max(ans,sum);
}
cout<<ans<<endl;
return ;
}
练习T6糖果传递
/*
problem:yibentonglian10005
date:2019/5/7
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e6+;
long long a[maxn],c[maxn];
long long total,ave,ans;
int n;
int main(){
cin>>n;
for(int i = ;i <= n;i++)scanf("%d",&a[i]),total += a[i];
ave = total/n;
for(int i = ;i <= n;i++)c[i] = c[i-]+a[i]-ave;
sort(c+,c++n);
int mid = (n+)>>;
for(int i = ;i <= n;i++)
ans += abs(c[mid]-c[i]);
printf("%lld\n",ans);
return ;
}
T1数列分段II
/*
problem:yibentong10000
date:2019/5/7
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 1e5+;
int a[maxn];
int n,m,l,r;
inline bool check(int x){
int ans = ,sum = ;
for(int i = ;i <= n;i++){
sum += a[i];
if(sum > x)ans++,sum = a[i];
}
if(ans <= m)return true;
return false;
}
int main(){
cin>>n>>m;
int Max = ,sum = ;
for(int i = ;i <= n;i++)scanf("%d",&a[i]),Max = max(Max,a[i]),sum += a[i];
l = Max,r = sum;
while(l <= r){
int mid = (l+r)>>;
if(check(mid))r = mid-;
else l = mid+;
}
cout<<l<<endl;
return ;
}
T2愤怒的牛
/*
problem:yibentong10001
date:2019/5/7
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e5+;
int a[maxn];
int n,m;
inline bool check(int x){
int ans = ;
int cnt = a[]+x;
for(int i = ;i <= n;i++){
if(a[i] < cnt)continue;
ans++;
cnt = a[i]+x;
}
return ans >= m;
}
int main(){
cin>>n>>m;
for(int i = ;i <= n;i++)scanf("%d",&a[i]);
sort(a+,a++n);
int l = ,r = a[n];
while(l <= r){
int mid = (l+r)>>;
if(check(mid))l = mid+;
else r = mid-;
}
cout<<r<<endl;
return ;
}
T3扩散
法一:Kruscal
/*
problem:yibentong10002
date:2019/5/11
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const ll maxn = 5e1+;
ll father[maxn],x[maxn],y[maxn];
ll n,cnt,sum;
struct edge{
ll x,y,w;
}e[maxn*maxn/];
ll dist(ll i,ll j){
return (abs(x[i]-x[j])+abs(y[i]-y[j])+)/;
}
ll cmp(edge a,edge b){
return a.w < b.w;
}
ll find(ll x){
if(father[x] == x)return x;
else return father[x] = find(father[x]);
}
void Kruscal(){
sort(e+,e++cnt,cmp);
for(ll i = ;i <= cnt;i++)
if(find(e[i].x) != find(e[i].y)){
father[find(e[i].x)] = find(e[i].y);
sum++;
if(sum == n-){
printf("%lld\n",e[i].w);
break;
}
}
}
int main(){
cin>>n;
for(ll i = ;i <= n;i++)scanf("%d%d",&x[i],&y[i]);
for(ll i = ;i <= n;i++)father[i] = i;
for(ll i = ;i <= n;i++)
for(ll j = i+;j <= n;j++){
cnt++;
e[cnt].x = i;
e[cnt].y = j;
e[cnt].w = dist(i,j);
}
Kruscal();
return ;
}
法二:Floyd
/*
problem:yibentong1000
date:2019/5/11
author:Lonely.Devil
*/ #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const ll maxn = 5e1+;
struct point{
ll x,y;
}p[maxn];
ll map[maxn][maxn];
ll n,ans;
inline ll Abs(ll x){
if(x < )x = -x;
return x;
}
inline ll Min(ll x,ll y){
return x < y ? x : y;
}
inline ll Max(ll x,ll y){
return x > y ? x : y;
}
inline ll dist(int i,int j){
return (Abs(p[i].x-p[j].x)+Abs(p[i].y-p[j].y)+)/;
}
inline void Floyd(){
for(ll k = ;k <= n;k++)
for(ll i = ;i <= n;i++)
for(ll j = ;j <= n;j++)
map[i][j] = min(map[i][j],max(map[k][j],map[i][k]));
}
int main(){
cin>>n;
for(ll i = ;i <= n;i++)scanf("%lld%lld",&p[i].x,&p[i].y);
for(ll i = ;i <= n;i++)
for(ll j = ;j <= n;j++)
if(i == j)map[i][j] = ;
for(ll i = ;i <= n;i++)
for(ll j = i+;j <= n;j++)
map[i][j] = map[j][i] = dist(i,j);
Floyd();
for(ll i = ;i <= n;i++)
for(ll j = i+;j <= n;j++)
if(ans < map[i][j])
ans = map[i][j];
cout<<ans<<endl;
return ;
}
LibreOJ一本通题解报告的更多相关文章
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...
- cojs 强连通图计数1-2 题解报告
OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...
- cojs 二分图计数问题1-3 题解报告
OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- CF1169(div2)题解报告
CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
随机推荐
- vagrant三网详解(团队/个人开发必看) 转
vagrant三网详解(团队/个人开发必看) Vagrant 中一共有三种网络配置,下面我们将会详解三种网络配置各自优缺点. 一.端口映射(Forwarded port) 顾名思义是指把宿主计算机 ...
- P2801 教主的魔法(分块入门)
两个月之前听yyr学长讲的分块,感觉是个很神奇的暴力,但到现在还是懵的一匹 #include<bits/stdc++.h> using namespace std; ; int belon ...
- Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock32 error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
今天安装完带图形界面的CentOS 7后,在Terminal中运行yum安装命令时报了以下错误: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- centos7之openvpn搭建
一.环境介绍 操作系统centos7.4 openvpn版本:openvpn-2.1 lzo版本:lzo-2.03 二.搭建 关闭firewalld防火墙,并设置开机不启动.关闭selinux sys ...
- python操作随笔
# -*- encoding: utf-8 -*-import urllib2from bs4 import BeautifulSoupimport re f1 = open('E:/1.txt')l ...
- JDK源代码学习-基础类
一.概述 1.Java,是一套语言规范,例如规定了变量如何定义.控制语句如何写等,提供基本的语法规范.JDK是java自带的一套调用组件,是对基本java语法规范的进一步封装,jdk中都是使用java ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)
题意:给出一条直线 ax +by+c=0 给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
- Linux lvs-DR模式配置详解
本篇文档主要是记录DR模式实现过程,以及各配置步骤的原理.“lvs三种模式工作原理”中描述了LVS的NAT.DR.TUN三种模式的工作原理. DR模式是通过director将报文源和目标MAC地址修改 ...
- [hosts]在hosts中屏蔽一级域名和二级域名的写法
一级域名,如baidu: 0.0.0.0 baidu.com 二级域名 如有道公开课 0.0.0.0 ke.youdao.com 不带协议名,不带www. 用127.0.0.1也可以.
- winform项目导入数据
一.点击导入按钮,弹出文件选择框 这个方法的使用要引用下面两个命名空间: using System.Windows.Forms;using DevExpress.XtraEditors; privat ...