目录

·贪心

·二分三分

网页跳转

解析啥的以后会有的

贪心目录

·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. js获取元素宽高、位置相关知识汇总

    常见clientWidth.clientHeight.offsetWidth.offsetLeft,clientX.scrollTop等词语,比较混乱,现在总结下他们的区别. 1. clientWid ...

  2. H5键盘事件处理

    if (/Android/gi.test(navigator.userAgent)) { const innerHeight = window.innerHeight; window.addEvent ...

  3. Vue.js 2.x笔记:指令(4)

    1. 内置指令 指令是Vue.js 中一个重要的特性,主要提供了一种机制将数据的变化映射为DOM 行为. Vue.js 本身提供了大量的内置指令来进行对DOM 的操作,同时可以开发自定义指令. 2. ...

  4. git在多迭代版本的应用

    名词解释: 1.迭代: 就是对于项目功能的一个分类.如项目需要新增一个地图功能,则地图功能是一个迭代. 2.gitlab机器人 操作: 1.如果将要进行一个新功能的开发,从稳定分支上拉取创建一个新的分 ...

  5. Java中的Null是什么?

    对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常(NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我认 ...

  6. POJ 1821 Fence (算竞进阶习题)

    单调队列优化dp 我们把状态定位F[i][j]表示前i个工人涂了前j块木板的最大报酬(中间可以有不涂的木板). 第i个工人不涂的话有两种情况: 那么F[i - 1][j], F[i][j - 1]就成 ...

  7. Magento composer 安装

    composer create-project --repository=https://repo.magento.com/ magento/project-community-edition:2.2 ...

  8. LeetCode--689_Maximum_Sum_of_3_NonOverlapping_Subarrays

    原题链接:点击这里 一道很水很水的背包问题? 大概算不上背包吧QAQ 自己的dp 真的是太差劲啦,以后每天一道LeetCode 备战秋招! package leetcode; public class ...

  9. 微信, qq 支付宝 等相关开发 资源 记录

    手机QQweb开发平台  api : http://open.mobile.qq.com/api/component/share qq 微信  分享 简介 :https://segmentfault. ...

  10. UVA - 11427 Expect the Expected (概率dp)

    Some mathematical background. This problem asks you to compute the expected value of a random variab ...