Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行
A
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a[];
int num[];
map<ll, int> mp;
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
cin >> a[i];
}
int anser = ;
for (int i = ; i <= n; i++)
{
memset(num, , sizeof(num));
int now = ;
for (int j = ; j < a[i].size(); j++)
{
int cur = a[i][j] - 'a';
if (!num[cur])
{
num[cur] = ;
now += (1LL << cur);
}
}
if (!mp[now])
{
anser++;
mp[now]++;
}
}
cout << anser << endl;
}
B
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a[];
ll num[];
ll ans[];
int main()
{
ll anser = ;
for (int i = ; i <= ; i++)
{
cin >> num[i];
}
for (int i = ; i <= ; i++)
{
ll now = ;
ll has;
for (int j = ; j <= ; j++)
{
ans[j] = num[j];
}
if (ans[i] == )
{
continue;
}
if (ans[i] >= )
{
ll bei = ans[i] / ;
has = ans[i] - * bei;
ans[i] = ;
for (int j = ; j <= ; j++)
{
ans[j] += bei;
}
int cur = i + ;
if (cur > )
{
cur -= ;
}
while (has)
{
ans[cur]++;
cur++;
if (cur > )
{
cur -= ;
}
has--;
}
}
else
{
has = ans[i];
ans[i] = ;
int cur = i + ;
if (cur > )
{
cur -= ;
}
while (has)
{
ans[cur]++;
cur++;
if (cur > )
{
cur -= ;
}
has--;
}
}
for (int j = ; j <= ; j++)
{
if (ans[j] % == )
{
now += ans[j];
}
}
anser = max(now, anser);
}
cout << anser << endl;
}
C
前缀和+二分
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll num[];
int getans(ll x)
{
int l = , r = n;
int mid, ans;
while (l <= r)
{
mid = (l + r) / ;
if (num[mid] > x)
{
ans = mid;
r = mid - ;
}
else
{
l = mid + ;
}
}
return ans;
}
int main()
{
ll now = ;
ll q;
cin >> n >> m;
for (int i = ; i <= n; i++)
{
cin >> num[i];
num[i] += num[i - ];
}
for (int i = ; i <= m; i++)
{
cin >> q;
now += q;
if (now >= num[n])
{
cout << n << endl;
now = ;
}
else
{
cout << n + - getans(now) << endl;
}
}
}
D
将点以离开原来所在直线的速度排序 相同速度的为一团
当且仅当两个速度方向一样(Vxi=Vxj Vyi=Vyj)的时候不会相交
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll cheng = ;
ll dian[];
ll k, anser;
ll sum = ;
ll kb;
ll vx, vy;
map<ll, ll> mp;
int main()
{
int n, m;
cin >> n;
cin >> k >> kb;
for (int i = ; i <= n; i++)
{
cin >> kb >> vx >> vy;
sum = 1LL * vx * (1LL * cheng + );
sum += vy;
anser -= 2LL * mp[sum];
mp[sum]++;
dian[i] = 1LL * vx * k - vy;
}
sum = ;
sort(dian + , dian + n + );
for (int i = ; i <= n; i++)
{
if (dian[i] == dian[i - ])
{
sum++;
}
else
{
anser += 1LL * sum * (sum - );
sum = ;
}
}
ll add = 1LL * sum * (sum - );
anser += add;
cout << anser << endl;
}
Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行的更多相关文章
- Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除
A. 全部空的放狗 B. 先O(NLOGNLOGN)处理出一个合数质因数中最大的质数是多少 因为p1 x1 x2的关系是 x2是p在x1之上的最小倍数 所以x1的范围是[x2-p+1,x2-1]要使最 ...
- Codeforces 1090J $kmp+hash+$二分
题意 给出两个字符串\(s\)和\(t\),设\(S\)为\(s\)的任意一个非空前缀,\(T\)为\(t\)的任意一个非空前缀,问\(S+T\)有多少种不同的可能. Solution 看了一圈,感觉 ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- Glider(前缀和+二分)
题目链接:Glider Gym-101911B 解题分析:下落的高度一定,是h.在没有气流的地方每秒下落1:所以可以转化为经过无气流地带的时间总长为h. 那么很显然从一个有气流地带的开始,选择下落,那 ...
- Acwing:102. 最佳牛围栏(前缀和 + 二分)
农夫约翰的农场由 NN 块田地组成,每块地里都有一定数量的牛,其数量不会少于1头,也不会超过2000头. 约翰希望用围栏将一部分连续的田地围起来,并使得围起来的区域内每块地包含的牛的数量的平均值达到最 ...
- Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...
- Codeforces Global Round 2 D 差分 + 前缀和 + 二分
https://codeforces.com/contest/1119/problem/D 题意 有n个数组,每个数组大小为\(10^{18}+1\)且为等差数列,给出n个数组的\(s[i]\),q次 ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- CodeForces - 948C(前缀和 + 二分)
链接:CodeForces - 948C 题意:N天,每天生产一堆雪体积 V[i] ,每天每堆雪融化 T[i],问每天融化了多少雪. 题解:对 T 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
随机推荐
- 职位-IT:软件设计师
ylbtech-职位-IT:软件设计师 软件设计师是指能根据软件开发项目管理和软件工程的要求,按照系统总体设计规格说明书进行软件设计,编写程序设计规格说明书等相应的文档的实用性人才.还能够组织和指导程 ...
- 服务器被攻击后当作矿机,高WIO
__ 矿机特点: 操作系统反应慢. wio 非常高,一般轻松达到50%,甚至达到100%. 在/root/ 下存在 .ddg 隐藏路径.路径中有nnnn.db 二进制文件. /tmp ./usr ...
- Jmeter(十)负载生成器
使用LoadRunner时, 产生负载会用到利器Load Generator, 来远程控制负载机进行测试. Jmeter也不例外, 由此可见, 工具与工具之间, 达到的目的必是相同, 只是手段不一样罢 ...
- 四十五:数据库之SQLAlchemy之subquery实现复杂查询
子查询让多个查询变成一个查询,只需要查找一次数据库,性能相对来讲更高效,不用写多个SQL语句就可以实现一些复杂的查询,在SQLAlchemy中要实现一个子查询,应该使用以下步骤:1.将子查询按照传统方 ...
- Dart学习笔记-运算符-条件表达式-类型转换
Dart学习笔记-运算符-条件表达式-类型转换 一.运算符 1.算术运算符 + (加)- (减)* (乘)/ (除)~/ (取整) %(取余) 2.关系运算符 == (等等) != (不等) > ...
- python3.5以后venv创建/激活/退出虚拟环境
1.创建虚拟环境 $ python3 -m venv <环境名称> 2.激活虚拟环境 $ source <环境名称>/bin/activate 3.关闭虚拟环境 $ deact ...
- 【Ruby on Rails 学习三】Ruby 基本数据类型(类、类的实例、对象)
数字.文本.范围.符合.True.False.Nil 1为什么是一个类的对象,使用methods方法可以查看一个对象的所有函数(方法) $ irb irb(main)::> => irb( ...
- 【VS开发】raw socket 的例子
raw socket 的例子 一. 摘要 Raw Socket: 原始套接字 可以用它来发送和接收 IP 层以上的原始数据包, 如 ICMP, TCP, UDP... int sockRa ...
- [Vuejs] 点击单选框触发两次点击事件的处理
<el-radio-group v-model="uploadStatus" class="upload-status-radio"> <el ...
- Qt - 获取本机网络信息
目的: 获取本机的主机名.IP地址.硬件地址等网络信息. 工具: 使用Qt提供的网络模块QtNetwork(pro文件里面加network): 使用Qt提供的类QHostInfo.QNetworkIn ...