A - Large Digits

思路:签到题,读入字符串即可。

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()
{
string a, b;
cin>>a>>b;
ll sum1 = 0, sum2 = 0;
for(int i=0; i<a.size(); i++) sum1 += a[i]-'0';
for(int i=0; i<b.size(); i++) sum2 += b[i]-'0';
cout<<max(sum1,sum2)<<endl;
return 0;
}

B - Gentle Pairs

思路:暴力统计,算斜率的时候直接看分子绝对值是否小于等于分母绝对值。

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;
}P; P a[maxn]; int main()
{
ll n = read();
rep(i,1,n) a[i].x = read(), a[i].y = read();
ll sum = 0;
rep(i,1,n) rep(j,i+1,n)
{
ll up = a[i].x - a[j].x;
ll down = a[i].y - a[j].y;
swap(up,down);
if(abs(up)<=abs(down) ) sum++;
}
cout<<sum<<endl;
return 0;
}

C - 1-SAT

思路:先Map记录,然后把有!的去掉头,看看剩下的是否存在即可。

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();
map<string,int> Map;
vector<string> item;
rep(i,1,n)
{
string s;
cin>>s;
Map[s] = 1;
item.pb(s);
}
int flag = 0;
rep(i,1,n)
{
if(item[i-1][0]=='!')
{
string t(item[i-1],1,item[i-1].size());
if(Map[t])
{
cout<<t<<endl;
flag = 1;
break;
}
}
}
if(!flag) cout<<"satisfiable"<<endl;
return 0;
}

D - Choose Me

思路:这题有个小wa点就是不能直接贪心拿和大的(有可能和比较小但是其中的第一个值很大)。

考虑因为要第二个人得分比第一个人高分,我们如果对一个人分析的话,第二个人最优的情况是全部都选上,就是所有的和。然后我们看要剔除尽可能的地点。

每次剔除,自身-sum,对方+第一个值, 相当于我 \(-sum-第一个值\)。 所以我们就按照2*第一个值 + 第二个值从小到大来排个序,然后按照这个顺序来剔除直到剩余值小于等于0即可。

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 Voter
{
ll aoki;
ll taka;
ll sum;
bool operator < (const Voter &a) const
{
return sum<a.sum;
}
}V; V a[maxn];
ll sum[maxn]; int main()
{
ll n = read();
rep(i,1,n) a[i].aoki = read(), a[i].taka = read(), a[i].sum = 2*a[i].aoki + a[i].taka;
sort(a+1,a+1+n);
ll cur = 0;
rep(i,1,n) cur += a[i].aoki + a[i].taka; rep(i,1,n)
{
cur -= a[i].sum;
if(cur<=0)
{
cout<<n-i+1<<endl;
break;
}
}
return 0;
}

E - Through Path

这题暴力不可取。因为每次询问的ab是直接相连的,所以可以从这里入手(一开始没看到是直接相连卡住了)。

我们假设1为根。若a的深度比b小的时候,也就是a是b的父节点,那么这个时候,从跟出发的所有子树中,剔除b及其子树都可以+x。

\(那我们就add[1] += x, add[b] -= x, 表示1结点下面的所有子树都+x,b及其子树都-x。\)

因为dfs的时候可以将父节点的增值信息传递下来,所以我们询问的时候只需要记录第一次发生改变的结点就行了。

若a是b的子树,那么这种情况只需要a的子树都+x,\(即add[a] += x。\)

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} }; vector<vector<int> > D(maxn);
ll n;
ll dep[maxn];
ll add[maxn];
ll a[maxn];
ll b[maxn]; void getDep(int cur, int step, int pre)
{
dep[cur] = step;
for(int i=0; i<D[cur].size(); i++)
{
int v = D[cur][i];
if(v!=pre) getDep(v,step+1,cur);
}
} void dfs(int cur, ll preSum, int pre)
{
add[cur] += preSum;
for(int i=0; i<D[cur].size(); i++)
{
int v = D[cur][i];
if(v!=pre) dfs(v,add[cur], cur);
}
} int main()
{
ll n = read();
rep(i,1,n-1)
{
ll x = read();
ll y = read();
D[x].pb(y);
D[y].pb(x);
a[i] = x;
b[i] = y;
}
getDep(1,1,-1);
ll q = read();
rep(i,1,q)
{
ll flag = read(), e = read(), x = read();
if(flag==1)
{
if(dep[a[e]] < dep[b[e]])
{
add[1] += x;
add[b[e]] -= x;
}
else
{
add[a[e]] += x;
}
}
else
{
if(dep[b[e]] < dep[a[e]])
{
add[1] += x;
add[a[e]] -= x;
}
else
{
add[b[e]] += x;
}
}
}dfs(1,0,-1);
rep(i,1,n) cout<<add[i]<<endl;
return 0;
}

AtCoder Beginner Contest 187 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 187 F - Close Group

    题目链接 点我跳转 题目大意 给你一张完全图,你可以删除任意数量的边 要求删除完后剩余的所有子图必须是完全图 问完全子图数量最少是多少 解题思路 定义 \(ok[i]\) 表示状态为 \(i\) 时所 ...

  6. AtCoder Beginner Contest 187

    A Large Digits int n; int main() { IOS; int a, b, resa = 0, resb = 0; cin >> a >> b; whi ...

  7. AtCoder Beginner Contest 154 题解

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

  8. AtCoder Beginner Contest 153 题解

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

  9. AtCoder Beginner Contest 177 题解

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

  10. AtCoder Beginner Contest 184 题解

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

随机推荐

  1. MySQL 的索引下推是什么?

    MySQL 的索引下推是什么? 索引下推(Index Condition Pushdown, ICP)是 MySQL 优化器在 InnoDB 存储引擎中引入的一种查询优化技术,从 MySQL 5.6 ...

  2. 如何使用Streamlit快速创建仪表盘?

    上文有快速带大家了解streamlit,因为工作需要,这两天尝试构建了仪表盘,也就是咱们常说的Dashboard,本篇文章将教你如何使用 Streamlit 快速创建一个简单的仪表盘. 前言 Stre ...

  3. Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题

    Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题 背景 在使用 Dify 框架进行开发时,遇到了两个主要的技术挑战: 代码节点连接到 PGSQL(Pos ...

  4. Lucas 定理简单证明

    前言 Oi wiki 和网上博客的证明都没完全看懂,最后还是自己推出来的..这里记录一下思路. Lucas 定理 对于质数 \(p\),$${n\choose m}\bmod p={\lfloor n ...

  5. 操作系统综合题之“用记录型信号量机制的wait操作和signal操作写出三个进程的同步代码(水果进箱问题-代码补充)”

    1.问题:假设一个水果赛选系统由三个进程A.B.C组成.进程A每次取一个水果,之后存放在货架F上,F的容量为每次只能存放一个水果.若货架上存放的是苹果则让进程B取出,并存放到苹果箱中:若货架上存放的是 ...

  6. 内网服务器离线安装部署 Ollama

    一.安装 Ollama 1.官网下载地址:Releases · ollama/ollama 2.cd至下载目录 3.执行二进制文件安装 sudo tar -C /usr -xzf ollama-lin ...

  7. 再论“ArcGIS AddIN之工具不可用”

    工作需要,开发arcgis的addin插件.从网上找了工程范例,编译dll,没有生成esriAddIn文件. 第二次,重新创建addin类型的动态库工程,从范例中复制类文件到工程中,编译dll,正常生 ...

  8. L3-2、引导 AI 推理思考 —— 从条件判断到链式推理

    一.什么是引导式推理(Self-Reasoning Prompt)? 引导式推理是一种提示工程技术,通过特定的提示结构引导AI模型进行逐步推理,使其能够像人类一样"思考"问题,而非 ...

  9. IDEA 设置类文件注释模板

      在写代码的时候,经常需要在类上编写注释,以标明这个类是谁写的和有什么作用,其实每次写都是那么几个相同的属性,比如作者.创建时间和功能描述等.在idea中,我们可以设置在创建类时自动加载注释,本文介 ...

  10. Java11 ThreadLocal的remove()方法源码分析

    1. ThreadLocal实现原理 本文参考的java 版本是11. 在讲述ThreadLocal实现原理之前,我先来简单地介绍一下什么是ThreadLocal.ThreadLocal提供线程本地变 ...