C. Dessert Café:

题意: 给你一个N个节点的树,树上有m个房子,问树上有几个节点是在两个房子之间的。

思路:我们发现只要是该节点的子树里包括了所有节点或者只有一个节点,那么这个结点肯定不是在两个房子之间的,至于证明我们可以画几幅图证明。代码实现的话,需要用到num[]数组记录该节点子树里房子个数,然后dfs一边即可。

代码:

int n,k;
vector<int>mp[maxn];
int num[maxn];
bool isA[maxn];
int ans=0;
void dfs(int u,int f)
{
int cnt=0;
for(int i=0;i<mp[u].size();i++)
{
int v=mp[u][i];
if(v!=f)
{
dfs(v,u);
num[u]+=num[v];
if(num[v]) cnt++;
}
}
if(num[u]!=k) cnt++;
//dbg(u);
if(cnt>=2&&!isA[u]) ans++;
//dbg(ans);
}
void run()
{
n=rd();
k=rd();
for(int i =1;i<n;i++)
{
int u=rd(),v=rd(),w=rd();
mp[u].push_back(v);
mp[v].push_back(u);
}
for(int i=0;i<k;i++)
{
int x=rd();
num[x]=1;
isA[x]=true;
ans++;
//cout<<ans<<" sss"<<endl;
}
dfs(1,-1);
cout<<ans<<endl;
}
signed main()
{
run();
return 0;
}

E - Imprecise Computer

思路:通过分析不难发现如果前面产生了1>2的错误判断,那么这个错误会一直影响到最后,然后我们只要在产生这样错误后对后面的d +1或者-1 直到最后消除影响,那么就可以构造成功,而且中途是不能出现d>=2 的情况。

代码实现:

int n;
int d[maxn];
void run()
{
n=rd();
for(int i=1;i<=n;i++) d[i]=rd();
bool flag=true;
for(int i=1;i<=n;i++)
{
if(d[i]>1) {
puts("NO");
return ;
}else if(d[i])
{
if(d[i+1]) d[i+1]--;
else d[i+1]--;
}
}
puts(d[n]==0?"YES":"NO");
}
signed main()
{
// int t=rd();
// while(t--)
run();
return 0;
}

2020-2021 ACM-ICPC, Asia Seoul Regional Contest的更多相关文章

  1. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  2. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  3. 2019-2020 ICPC, Asia Jakarta Regional Contest

    目录 Contest Info Solutions A. Copying Homework C. Even Path E. Songwriter G. Performance Review H. Tw ...

  4. 2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

    As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC ...

  5. 2018-2019 ACM-ICPC, Asia Seoul Regional Contest

    ProblemA Circuits Solved. 题意: 有$n$个矩形,可以放两条平行与$x$轴的线,求怎么放置两条无线长的平行于$x$轴的线,使得他们与矩形相交个数最多 如果一个矩形同时与两条线 ...

  6. 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K

    传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...

  7. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

  8. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  9. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  10. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

随机推荐

  1. Dapr 交通控制示例

    Dapr 已在塔架就位 将发射新一代微服务 牛年 dotnet云原生技术趋势 Dapr是如何简化微服务的开发和部署 前面几篇文章都是从大的方面给大家分享Dapr 能帮助我们解决什么问题,微软从开源到1 ...

  2. chmod +x vs chmod 755

    chmod +x vs chmod 755 What is the difference between "chmod +x" and "chmod 755"? ...

  3. 微信小程序-生命周期图解

    微信小程序-生命周期图解 小程序生命周期 App 生命周期 https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.htm ...

  4. WebRTC in Action

    WebRTC in Action https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API https://codelabs.develo ...

  5. MongoDB Manually config

    MongoDB Manually config macOS 10.15.x path error exception in initAndListen: NonExistentPath: Data d ...

  6. ES Next & Arrow function & Promise & Iterator & Generator yield & Async Await

    ES Next & Arrow function & Promise & Iterator & Generator yield & Async Await co ...

  7. Raspberry Pi & Raspberry Pi 4

    Raspberry Pi & Raspberry Pi 4 pdf https://www.raspberrypi.org/magpi/issues/beginners-guide-2nd-e ...

  8. how to change svg polygon size by update it's points in js

    how to change svg polygon size by update it's points in js matrixTransform https://stackoverflow.com ...

  9. JPG学习笔记4(附完整代码)

    #topics h2 { background: rgba(43, 102, 149, 1); border-radius: 6px; box-shadow: 0 0 1px rgba(95, 90, ...

  10. MapReduce原理及简单实现

    MapReduce是Google在2004年发表的论文<MapReduce: Simplified Data Processing on Large Clusters>中提出的一个用于分布 ...