目录

·贪心

·二分三分

网页跳转

解析啥的以后会有的

贪心目录

·T1活动安排

·T2种树

·T3喷水装置

·T4加工生产调度

·T5智力大冲浪

·练习T1

·练习T2

·练习T3

·练习T4

·练习T5

·练习T6

二分三分目录

·T1数列分段II

·T2愤怒的牛

·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一本通题解报告的更多相关文章

  1. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

  2. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

  3. cojs 二分图计数问题1-3 题解报告

    OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...

  4. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  5. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  6. 题解报告: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 ...

  7. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  8. CF1169(div2)题解报告

    CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...

  9. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

随机推荐

  1. ABP实践(2)-ASP.NET Core 2.x版本EntityFrameworkCore(EF)使用mysql数据库

    上一篇中EntityFrameworkCore默认使用的是微软的sql server,本篇改为mysql步骤如下: 1,在基础层xxx.EntityFrameworkCore依赖项添加Pomelo.E ...

  2. MVC中使用Hangfire按秒执行任务

    更新Hangfire版本到1.7.0,才支持使用按秒循环任务执行 RecurringJob.AddOrUpdate("test",()=>writeLog("每20 ...

  3. Lazy 延迟加载

    问题:最近遇到一个项目遇到一个问题(很久的项目,现阶段主要维护),程序初始化的时候比较慢,最后查原因的时候发现是因为一个类的构造方法里面有些逻辑, 解决办法:希望在使用的时候再进行加载,最后想到了延迟 ...

  4. [题解]邮递员寄信(luoguP1629)

    题目来源:luoguP1629 题目描述 有一个邮递员要送东西,邮局在结点1.他总共要送N-1样东西,其目的地分别是2-N.由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有M条道路,通过每条 ...

  5. How to Change Error Message Colors in Windows 10 PowerShell Console

    While this was a really easy way to change some of the settings, what if you want to do more extensi ...

  6. (十一)QPainter绘图, QPixmap,QImage,QPicture,QBitmap

    #include "widget.h" #include "ui_widget.h" #include <QPainter> #include &l ...

  7. JavaScript中数据类型判断

    做判断前先来了解下 JavaScript 中的基本数据类型 一.七大数据类型 基本类型:存储在栈( stack )中 Number(包括整型和浮点型) String. Boolean. Symbol ...

  8. showdoc app接口文档编写利器

    通过朋友介绍,才知道有这么好的一个在线接口编写文档开源项目,非常感谢原作者的贡献 ShowDoc介绍 关于ShowDoc的介绍,请访问:http://blog.star7th.com/2015/11/ ...

  9. redis基础知识思维导图

    看到一张redis的基础知识思维导图,比较清晰, 但是没有标明来源,希望知道的给个地址,我也好说明来源 图大小有1M多.在博客上看比较模糊,可以先下载下来查看,或者在浏览器新标签中打开图片查看,就比较 ...

  10. [Android] Android Error: Suspicious namespace and prefix combination [NamespaceTypo] when I try create Signed APK

    Error: Suspicious namespace and prefix combination [NamespaceTypo] 解决办法: xmlns:app 的值改为: xmlns:app=& ...