A - New Generation ABC

思路:分段讨论

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; int main()
{
ll n = read();
if(n>=1&&n<=125) cout<<4<<endl;
else if(n>=126&&n<=211) cout<<6<<endl;
else cout<<8<<endl;
return 0;
}

B - How many?

思路:暴力枚举即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; int main()
{
ll s = read(), t = read();
ll ans = 0;
rep(i,0,s) rep(j,0,s) rep(k,0,s) if(i+j+k<=s&&i*j*k<=t) ans++;
cout<<ans<<endl;
return 0;
}

C - Distribution

思路:前i个的最优解,由前i-1个最优解 + \(S_{i-1}\) 过来,或者直接选当前\(T_{i}\), 由于是个环,所以多复制一段1-n到a数组后面,遍历1-2n即可得到每个最优解。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 4e5+200;
const ll inf=0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll each[maxn];
ll s[maxn];
ll t[maxn]; int main()
{
ll n = read();
rep(i,0,2*n+1) each[i] = 1e15;
ll pre = inf;
rep(i,1,n) s[i] = read(); rep(i,n+1,2*n) s[i] = s[i-n];
rep(i,1,n) t[i] = read(); rep(i,n+1,2*n) t[i] = t[i-n];
rep(i,1,n*2)
{
each[i] = min(min(t[i],each[i-1]+s[i-1]),each[i]);
}
rep(i,n+1,n*2) cout<<each[i]<<endl;
return 0;
}

D - Sum of Maximum Weights

思路:考虑从权值从小到大逐个每个边,使得当前边讨论时,只需要加上这条边两端点的个数相乘,再乘上权值(\(ans+= numx* numy * val\))。这一步操作利用并查集维护即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; typedef struct Pos
{
ll x;
ll y;
ll val;
bool operator < (const Pos &a) const
{
return val < a.val;
}
}P;
P a[maxn]; ll fa[maxn];
ll num[maxn]; ll get(ll x)
{
return fa[x] = (fa[x]==x?x:get(fa[x]));
} void solve()
{
ll n = read();
rep(i,1,n) fa[i] = i, num[i] = 1;
rep(i,1,n-1) a[i].x = read(), a[i].y = read(), a[i].val = read();
sort(a+1,a+1+n-1);
ll ans = 0;
rep(i,1,n-1)
{
ll x = a[i].x, y = a[i].y, val = a[i].val;
ll fx = get(x), fy = get(y);
if(fx != fy)
{
ll numx = num[fx];
ll numy = num[fy];
ans += numx*numy*val;
fa[fy] = fx;
num[fx] += num[fy];
//cout<<i<<' '<<x<<' '<<y<<' '<<val<<' '<<numx<<' '<<numy<<' '<<val<<endl;
}
}
cout<<ans<<endl;
} int main()
{
solve();
return 0;
}

E - Packing Under Range Regulations

思路:先考虑暴力对每个点遍历时的策略:对于当前i,我要对所有L<=i的区间里面,贪心挑一个R最小的(R小要尽快处理掉),这样对每个i都如此维护的话,一旦发现这个挑出来的R<i,则不合法,最后检验是否每个区间都被挑完了。由于i范围很大,所以考虑优化,发现要满足L<=i,有很多点可以直接跳着走,所以当发现没有区间可以挑的时候,可以直接跳到后面最近的L上,如此往复即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; typedef struct Pos
{
ll l;
ll r;
bool operator < (const Pos &a) const
{
return r > a.r;
}
}P;
P a[maxn]; bool cmp(P a, P b)
{
return a.l < b.l;
} int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n) a[i].l = read(), a[i].r = read();
sort(a+1,a+1+n,cmp);
priority_queue<P,vector<P> > q;
ll cnt = 0;
int id = 1;
int pos = 1;
while(id<=n||q.size())
{
while(id<=n&&a[id].l<=pos) q.push(a[id]), id++;
if(q.size()&&q.top().r<pos) break;
if(q.size()&&q.top().r>=pos) q.pop(), cnt++;
if(q.empty()&&id<=n) pos = a[id].l;
else if(q.size()) pos++;
}
puts(cnt==n?"Yes":"No");
}
return 0;
}

AtCoder Beginner Contest 214 ABCDE 题解的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  3. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  4. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  5. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  6. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  7. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  10. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

随机推荐

  1. 在线带壳屏幕截图工具推荐:MockUPhone

    简介 MockUPhone是一款免费的在线工具,用于生成带壳屏幕截图.这款工具主要面向开发者.设计师以及产品经理等人群,他们可以利用MockUPhone将UI设计或屏幕截图展示在各种不同类型的设备模型 ...

  2. python满足任意一个条件均认为假设有效(执行if内脚本)if any的用法

    下方代码,判断sta内是否包含s数组内的数字,只要包含任意一个输入ok,否则输出no s=['3','8','9'] sta='59' if s[0] in sta or s[1] in sta or ...

  3. Mybatis 框架课程第三天

    目录 1 Mybatis连接池与事务深入 1.1 Mybatis的连接池技术 1.1.1 Mybatis连接池的分类 1.1.2 Mybatis中数据源的配置 1.2 Mybatis 的事务控制 1. ...

  4. Web前端入门第 47 问:CSS @media 媒体查询不要只会视口宽度适配

    @media 媒体查询的出现解决了什么问题? 曾经,一个网页要兼容移动端和 PC 端,前端的代码复杂度嗖嗖嗖的飙升,需要使用多套代码对各种屏幕尺寸做适配. @media 的出现解决了 CSS 中无法适 ...

  5. Notepad++之"常用技术"

    一.^ 前面 数据准备 二.$ 后面 准备 结果

  6. k8s之数据存储

    查看k8s支持的存储类 kubectl explain pods.spec.volumes 1.emptydir kubectl explain pods.spec.volumes.emptyDir ...

  7. 操作系统:Linux如何获取所有设备信息

    本节了解下Linux是如何管理设备的,将从Linux如何组织设备开始,然后研究设备相关的数据结构,最后写一个Linux设备驱动实例. 感受一下Linux下的设备信息 Linux的设计哲学是一起皆是文件 ...

  8. 开发一组交易信号--K线与10均线的关系

    K线上穿/下穿10日均线,如图所示: 类似于,之前写的基于聚宽平台写的一个典型的双均线策略思想类似,当K线上穿10日均线时,发出买入信号,当K先下穿10日均线时,发出卖出信号. 比较当前的收盘价和MA ...

  9. 一个使用 WPF 开发的 Diagram 画板工具(包含流程图FlowChart,思维导图MindEditor)

    前言 今天大姚给大家分享一个使用 WPF 开发的 Diagram 画板工具(包含流程图FlowChart,思维导图MindEditor):AIStudio.Wpf.Diagram. 项目介绍 AISt ...

  10. .NET周刊【5月第4期 2025-05-25】

    国内文章 .NET 的全新低延时高吞吐自适应 GC - Satori GC https://www.cnblogs.com/hez2010/p/18889954/the-new-satori-gc-f ...