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 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
随机推荐
- jqGrid细节备注—jqGrid中自定义格式,URL格式
本文来自:http://cnn237111.blog.51cto.com/2359144/782137 jqGrid中自定义格式,URL格式 当官方自带的showlink用起来不是十分顺手,因此可以考 ...
- Selenium 2自动化测试实战2(数组与字典)
一.数组与字典 1.数组 数组用方括号([])表示,里面的每一项用逗号(,)隔开 Prthon允许在数组里面任意地放置数字或字符串.需要注意的是,数组下标是从0开始的,所以,lists[0]会输出数组 ...
- oracle审计登录失败用户
使用sys账号连接数据库,然后执行如下步骤: 1.alter system set audit_trail=db scope=spfile; 2.重启数据库服务 3.AUDIT SESSION WHE ...
- Object Creation
Although using the object constructor or an object literal are convenient ways to create single obje ...
- WEB应用服务器都有哪些?
大型WEB服务器在UNIX和Linux平台下使用最广泛的免费HTTP服务器是W3C.NCSA和APACHE服务器,而Windows平台NT/2000/2003使用IIS的WEB服务器.在选择使用WEB ...
- Stream parallel并行流的思考
1.并行流并不一定能提高效率,就和多线程并不能提高线程的效率一样 因为引入并行流会引起额外的开销,就像线程的频繁上下文切换会导致额外的性能开销一样,当数据在多个cpu中的处理时间小于内核之间的传输时间 ...
- JSON中文处理类实例
$array = array( 'Name'=>'络恩', 'Age'=>24); $post=my_json_encode($array); // 这个函数是判断版本,如果是搞版本的则直 ...
- 主机加固之win7
这套主机加固方案很简单,一步一步按着顺序来弄就可以,部分步骤还配有相关图片.可以先用虚拟机来做一次加固,以防弄错后不好恢复.记得弄个快照,以防万一.下次有空写个win7暴力破解~ 1. 配置管理 1. ...
- 11.8 Springcloud项目简介
各位领导好,我从毕业后做了两年Java开发工程师,刚开始都是一些SSM框架的项目,但是由于技术不断更新,微服项目成为必然的趋势,大约在做了1年的SSM框架,之后开始接触微服项目,前后经理过Dubbo和 ...
- DSP28335 GPIO学习
根据网络资料以及以下两篇博客整理 http://blog.sina.com.cn/s/blog_86a6035301017rr7.html http://blog.csdn.net/hmf123578 ...