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. 配置jenkins的shell自动打包的脚本

    #!/bin/bash#服务名称SERVER_NAME=jenkins-test# 源jar路径,mvn打包完成之后,target目录下的jar包名称,也可选择成为war包,war包可移动到Tomca ...

  2. virtualbox怎么设置鼠标在物理机和虚拟机间切换

    一.先打开管理,在"全局设定"中选择"热键",会看到如下图所示的内容,默认使用右ctrl键让鼠标离开虚拟机

  3. 🎀java-自定义日志注解

    简介 创建自定义日志注解,对相关接口记录请求日志. 环境 SpringBoot 实现 注解定义 定义注解类 package com.zk.app.annotation; import com.zk.a ...

  4. MySQL 中 AUTO_INCREMENT 列达到最大值时会发生什么?

    在MySQL中,AUTO_INCREMENT列用于自动生成唯一的数字值,通常用于主键.当AUTO_INCREMENT列达到最大值时,会发生以下几种情况,具体取决于列的数据类型以及MySQL的配置. 对 ...

  5. CentOS安装msf

    cd /opt curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/met ...

  6. Maven版本号管理规范:为何父POM是统一依赖版本的最佳实践?

    结论先行 在Maven多模块项目中,依赖的版本号应集中定义在父POM的<dependencyManagement>中,子模块通过继承父POM来引用版本号,通常无需在子POM中重复声明.这能 ...

  7. 牛客小白月赛111 E 构造矩形

    E 构造矩形 原题链接:https://ac.nowcoder.com/acm/contest/102742/E 思路: 这种询问方案数或者"价值"的题,通常解法要么是维护前缀信息 ...

  8. C++11 Lambda表达式(匿名函数)详解

    使用STL时,往往会大量用到函数对象,为此要编写很多函数对象类.而有的函数对象类只用定义一个对象,而且这个对象也只使用一次,那编写这样一个函数对象就很浪费了.而且有时这定义函数对象类的地方和使用函数对 ...

  9. SVM回归

    SVM回归任务是限制间隔违规情况下,尽量防止更多的样本在"街道"上."街道"的宽度由超参数\(\epsilon\)控制 在随机生成的线性数据上,两个线性SVM回 ...

  10. C#中扩展方法无法获得多态性的行为

    在C#中,扩展方法(Extension Methods)是一种用于给现有类型添加新方法的技术.但是,扩展方法无法实现多态性的行为,因为它们是静态方法,它们的行为是在编译时确定的,而不是在运行时. 多态 ...