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 扩展欧几里得方块内光线反射的更多相关文章

  1. [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)

    Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...

  2. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  3. 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions

    题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...

  4. [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 ...

  5. [POJ1845&POJ1061]扩展欧几里得应用两例

    扩展欧几里得是用于求解不定方程.线性同余方程和乘法逆元的常用算法. 下面是代码: function Euclid(a,b:int64;var x,y:int64):int64; var t:int64 ...

  6. 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 ...

  7. Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换

    A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...

  8. 【线段树/数学/扩展欧几里得】 Bzoj 3913:奇数国

    Description 在一片美丽的大陆上有100000个国家,记为1到100000.这里经济发达,有数不尽的账房,并且每个国家有一个银行.某大公司的领袖在这100000个银行开户时都存了3大洋,他惜 ...

  9. 【数论】【扩展欧几里得】Codeforces Round #484 (Div. 2) E. Billiard

    题意:给你一个台球桌面,一个台球的初始位置和初始速度方向(只可能平行坐标轴或者与坐标轴成45度角),问你能否滚进桌子四个角落的洞里,如果能,滚进的是哪个洞. 如果速度方向平行坐标轴,只需分类讨论,看它 ...

随机推荐

  1. php array function

    说明:不特殊说明都支持php4,5,7 参考:https://www.php.net/manual/zh/ref.array.php   is_array ( mixed $var ) : bool ...

  2. NavisWorks连接外部数据库,为模型附加属性

    可以直接从Navisworks 文件连接到外部数据库,并在场景中的对象与数据库表中的字段之间创建链接以引入额外特性. 1.连接mdb数据库 新建数据连接 单击“新建”按钮,新建数据连接,输入一个名称, ...

  3. Android 中布局的优化措施都有哪些?

    1.尽可能减少布局的嵌套层级可以使用 sdk 提供的 hierarchyviewer 工具分析视图树,帮助我们发现没有用到的布局.2.不用设置不必要的背景,避免过度绘制比如父控件设置了背景色,子控件完 ...

  4. ArcGISDynamicMapServiceLayer 和 ArcGISTiledMapServiceLayer 区别

    ArcGISDynamicMapServiceLayer(动态地图服务)通常用于实时显示经常变化的数据,支持控制单个图层可见性,可动态投影.但缺点是显示效果较差,整个服务出图较慢:ArcGISTile ...

  5. loadrunner 场景设计-手工场景方案(Schedule)设计 Part 1

    参考:http://blog.sina.com.cn/s/articlelist_5314188213_1_1.html loadrunner 场景设计-手工场景方案(Schedule)设计 Part ...

  6. Python文件重命名代码

    import os def re_name(path): for file in os.listdir(path): file_path = os.path.join(path, file) # 判断 ...

  7. Python学习之==>面向对象编程(二)

    一.类的特殊成员 我们在Python学习之==>面向对象编程(一)中已经介绍过了构造方法和析构方法,构造方法是在实例化时自动执行的方法,而析构方法是在实例被销毁的时候被执行,Python类成员中 ...

  8. Redis 入门 3.2.4 命令拾遗

    Redis 入门 3.2 字符串类型 3.2.4 命令拾遗 1. 增加指定的整数 INCRBY key increment   INCRBY命令与INCR命令基本一样,只不过前者可以通过increme ...

  9. Unity2D RPG游戏开发日志

    一.游戏构建设计 场景设计:地面的每一层用unity的TiledMap来设计,首先第一层为地面层,也就是地形的大部分区域的图块:第二层为覆盖层,如图中蓝色线圈起来的柱子的上半部分,由于玩家可以在柱子背 ...

  10. C#学习笔记一(概念,对象与类型,继承)

    一.基础 1.CLR为公共语言运行库,类似于JVM 2..NET Framwork是一个独立发布的程序包,其包含了CLR,类库及相关的语言编辑器等工具,类似于JDK,除了C#,还有其他几种语言在CLR ...