Codeforces 982 树边两端点计数偶数连通块 鲨鱼活动最小K最大location 扩展欧几里得方块内光线反射
A
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = ;
inline int readint()
{
char c = getchar();
int ans = ;
while (c < '' || c > '')
{
c = getchar();
}
while (c >= '' && c <= '')
{
ans = ans * + c - '', c = getchar();
}
return ans;
}
int main()
{
int n;
n = readint();
string a;
cin >> a;
if (a.size() == )
{
if (a[] == '')
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
}
else
{
if (a[] + a[] != '' + '')
{
cout << "No" << endl;
return ;
}
if (a[a.size() - ] + a[a.size() - ] != '' + '')
{
cout << "No" << endl;
return ;
}
for (int i = ; i < a.size() - ; i++)
{
if (a[i] == '')
{
if (a[i - ] == '' && a[i + ] == '')
{
cout << "No" << endl;
return ;
}
}
else
{
if (a[i - ] == '' || a[i + ] == '')
{
cout << "No" << endl;
return ;
}
}
}
cout<<"Yes"<<endl;
}
return ;
}
B
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = ;
inline int readint()
{
char c = getchar();
int ans = ;
while (c < '' || c > '')
{
c = getchar();
}
while (c >= '' && c <= '')
{
ans = ans * + c - '', c = getchar();
}
return ans;
}
priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > quemax;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > quemin;
int visit[N];
int main()
{
int now;
pair<int, int> cnt;
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
now = readint();
quemin.push(make_pair(now, i));
}
string a;
cin >> a;
int value, aim;
for (int i = ; i < a.size(); i++)
{
if (a[i] == '')
{
cnt=quemin.top();
quemin.pop();
cout<<cnt.second<<" ";
quemax.push(cnt);
}
else
{
cnt=quemax.top();
quemax.pop();
cout<<cnt.second<<" ";
}
}
return ;
}
C. Cut 'em all!
问你有几条边满足这条边两边的子树节点都是偶数个的
解:
当N为奇数时答案明显不存在
因为一个树的节点要不在一条边的左边 要不就在右边 所以从叶子开始往上DP 记录一个节点子树的节点数
如果节点数是偶数 那么因为节点总数是偶数 所以偶数-偶数为偶数(除了当节点数等于节点总数的情况那时候为0)
所以该点的一条边会有一个贡献
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = ;
inline int readint()
{
char c = getchar();
int ans = ;
while (c < '' || c > '')
{
c = getchar();
}
while (c >= '' && c <= '')
{
ans = ans * + c - '', c = getchar();
}
return ans;
}
vector<int> f[N];
int du[N];
int ans[N];
int n;
int u, v;
int aim;
int number = ;
int getans(int x, int pre)
{
ans[x] = ;
int len = f[x].size();
if (len == && x != aim)
{
return ans[x];
}
for (int i = ; i < len; i++)
{
int to = f[x][i];
if (to == pre)
{
continue;
}
getans(to, x);
ans[x] += ans[to];
}
if(ans[x]%==&&ans[x]!=n)
number++;
return ans[x];
}
int main()
{
n = readint();
if (n % )
{
cout << - << endl;
return ;
}
for (int i = ; i <= n - ; i++)
{
u = readint(), v = readint();
f[u].push_back(v);
f[v].push_back(u);
du[u]++, du[v]++;
}
for (int i = ; i <= n; i++)
{
if (du[i] == )
{
aim = i;
getans(i, -);
break;
}
}
cout<<number<<endl;
return ;
}
D. Shark
给你N个数字的一个数列 每个数字表示鲨鱼在第i天活动的距离
假设鲨鱼活动的距离小于K则不会移动location 不小于则移动 (移动是单方向的 不会回去)
问你找一个最小的K使得location的数量最大且同时鲨鱼在每个location的天数相同
解:
其实就是用带大小的并查集找一个数 使得比他小的数在原数列中相连的为一块 要求块内数的数量一样且块的数量尽量多
先用一个num数组表示数 另一个数组index表示下标 然后用num给index从小到大排序 再遍历从而保证数的出现是从小到大的
sum[i]表示 以第 i 位置及其旁边不大于它的连续的数的集合大小 而cntsum[i]表示大小为i的集合有几个
每次遍历一个位置如果它两边有比它小的数就用并查集把它俩并起来 同时维护好并查集的大小
如果碰到num[aim+1]!=num[aim]或者到头i==n的情况 同时满足该并查集大小*并查集内元素数目等于现在遍历到的总数目 就是合法的 尝试更新答案
/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
using namespace std;
typedef long long ll;
inline int readint()
{
char c = getchar();
int ans = ;
while (c < '' || c > '')
{
c = getchar();
}
while (c >= '' && c <= '')
{
ans = ans * + c - '', c = getchar();
}
return ans;
}
const long long mod = 1e9 + ;
const int N = 1e5 + ;
int n;
int ansnum = ;
int ans;
int num[N];
int index[N];
int father[N];
int sum[N];
int cntsum[N];
bool cmp(int x, int y)
{
return num[x] < num[y];
}
int findfather(int x)
{
if (father[x] != x)
{
return findfather(father[x]);
}
return x;
}
void merge(int x, int y)
{
x = findfather(x);
y = findfather(y);
if (!y) //保证合并的数是不大于num[aim]的数
{
return ;
}
cntsum[sum[x]]--, cntsum[sum[y]]--;
sum[x] += sum[y];
father[y] = x;
cntsum[sum[x]]++;
}
int main()
{
n = readint();
for (int i = ; i <= n; i++)
{
num[i] = readint();
index[i] = i;
}
sort(index + , index + + n, cmp);
int value, aim;
int now = ;
for (int i = ; i <= n; i++)
{
aim = index[i];
father[aim] = aim;
now++;
sum[aim] = ;
cntsum[]++;
merge(aim, aim - ), merge(aim, aim + ); //尝试合并旁边的数
if ((i == n || num[aim + ] != num[aim]) && now == cntsum[sum[findfather(aim)]]*sum[findfather(aim)])
{
if (cntsum[sum[findfather(aim)]] > ansnum)
{
ansnum = cntsum[sum[findfather(aim)]];
ans = num[aim] + ;
}
}
}
cout << ans << endl;
return ;
}
E
Exgcd:对于非负的两个整数a,b 一定存在整数 n,m 使得 a*n+b*m=gcd(a,b)
给你一个N*M的方块 一个点 一个方向向量(与边界平行或者成45度) 点碰到方块边界是完全弹性碰撞
问你这个点朝这个方向运动最后会不会落入四个角会的话落入哪个角

转载自:https://www.cnblogs.com/zhouzhendong/p/9055728.html
解:
画一组数据
5 3 4 0 1 1

通过对称,画成这样

然后问题就大致变成了求直线到达的第一个满足n|Tx m|Ty的点(Tx,Ty)
为了方便,我们再把原图画成这样:


Codeforces 982 树边两端点计数偶数连通块 鲨鱼活动最小K最大location 扩展欧几里得方块内光线反射的更多相关文章
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...
- [codeforces 200 E Tractor College]枚举,扩展欧几里得,三分
题目出自 Codeforces Round #126 (Div. 2) 的E. 题意大致如下:给定a,b,c,s,求三个非负整数x,y,z,满足0<=x<=y<=z,ax+by+cz ...
- [POJ1845&POJ1061]扩展欧几里得应用两例
扩展欧几里得是用于求解不定方程.线性同余方程和乘法逆元的常用算法. 下面是代码: function Euclid(a,b:int64;var x,y:int64):int64; var t:int64 ...
- Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x·a + y·b = n】
B. Proper Nutrition time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换
A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...
- 【线段树/数学/扩展欧几里得】 Bzoj 3913:奇数国
Description 在一片美丽的大陆上有100000个国家,记为1到100000.这里经济发达,有数不尽的账房,并且每个国家有一个银行.某大公司的领袖在这100000个银行开户时都存了3大洋,他惜 ...
- 【数论】【扩展欧几里得】Codeforces Round #484 (Div. 2) E. Billiard
题意:给你一个台球桌面,一个台球的初始位置和初始速度方向(只可能平行坐标轴或者与坐标轴成45度角),问你能否滚进桌子四个角落的洞里,如果能,滚进的是哪个洞. 如果速度方向平行坐标轴,只需分类讨论,看它 ...
随机推荐
- vue问题二:vue打包时产生的问题
vue项目打包问题:vue中默认的config/index.js的配置的详细理解: 参考文档:https://blog.csdn.net/qq_34611721/article/details/809 ...
- netfilter/iptables 防火墙
目录 文章目录 目录 iptables 与 netfilter 工作机制 规则(Rules) 链(chain) 表(tables) 网络数据包通过 iptables 的过程 总结链.表和规则的关系 i ...
- 对redis的一些理解
缓存就是在内存中存储的数据备份,当数据没有发生本质变化的时候,我们避免数据的查询操作直接连接数据库,而是去 内容中读取数据,这样就大大降低了数据库的读写次数,而且从内存中读数据的速度要比从数据库 ...
- 【miscellaneous】华为智能视频监控系统设计解决方案
[导读] 近年来,随着经济的快速增长.社会的迅速进步,校园.工厂园区.中小企业.楼宇等领域对安全防范和现场记录报警系统的需求与日俱增,视频监控在工作.生活各方面得到了非常广泛的应用. 1.中小型视频监 ...
- webdriver中判断元素是否存在的方法
selenium.webdriver中没有内置的判断元素是否存在的方法,所以定义一个方法,如果找到该元素则返回True,否则返回False: from selenium import webdrive ...
- Spring boot 整合 shiro 出现 org.apache.shiro.UnavailableSecurityManagerException: 错误
最开始参考的是这个 文档 但是并没有解决我的问题,因为他的配置和我的是一样(差不多)的 https://www.cnblogs.com/ginponson/p/6217057.html 然后看到此篇博 ...
- java方法形参是引用类型
public void 方法名(Student s) 这里形参需要的是该类的对象或者子类对象(父类引用子类对象). 1.若为普通类:则可传入该类的实例对象即可,方法名(new Student()): ...
- Java基础(入门Java)
今天是学习Java的第一天,为了保证在暑假里持续高效的学习,决定每周写一篇博客汇报总结当周进度,以此来督促自己不断的向更深更远的方向迈进.Java刚刚入门,看到的人若觉得某些地方不妥欢迎进行批评指导, ...
- 初步学习jquery学习笔记(三)
jQuery学习笔记三 jquery停止动画 stop函数的初步功能 <!DOCTYPE html> <html lang="en"> <head&g ...
- noip2015day2-运输计划
题目描述 公元$ 2044 $年,人类进入了宇宙纪元. \(L\) 国有 \(n\) 个星球,还有 \(n-1\) 条双向航道,每条航道建立在两个星球之间,这 \(n-1\) 条航道连通了 \(L\) ...