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 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
随机推荐
- Linux 下 *.tar.gz 文件解压缩命令及错误处理
1.压缩命令: 命令格式: tar -zcvf 压缩文件名 .tar.gz 被压缩文件名 可先切换到当前目录下,压缩文件名和被压缩文件名都可加入路径. 2.解压缩命令: 命令格式: tar -zxvf ...
- 代码实现:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%; 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%; 20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%; 60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元
import java.util.Scanner; /* 企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成 ...
- Git使用手册/Git教程:git fetch 将远程仓库的分支及分支最新版本代码拉取到本地
相关文章: 关于验证是否存在ssh配置以及生成SSH Key的方法可以参照文章:Git使用手册:生成SSH Key 关于SSH Key的使用和公钥在gitHub.gitLab的配置等,请参考文章:Gi ...
- Egret入门学习日记 --- 第二篇 (书籍的选择 && 书籍目录 && 书中 3.3 节 内容)
第二篇 (书籍的选择 && 书籍目录 && 书中 3.3 节 内容) 既然选好了Egret,那我就要想想怎么学了. 开始第一步,先加个Q群先,这不,拿到了一本<E ...
- sql语言(mysql)
一.SQL语言 1.DDL (Data Definition Language) 数据库定义语言 2.DML(Data Manipulation Language) 数据库操作语言 3.DQL (Da ...
- python3 selenuim PC端使用chrome模拟手机进行H5自动化
情况说明:初次在做PC端使用chrome进行H5自动化测试时,以为和app端自动化一样使用click()就可以对按钮进行点击,找了好几天也没有找到解决方法,有些人说是工程问题,有些人是使用微信进行H5 ...
- Confluence6.9配置邮件服务器
一.调整confluence服务 1.在confluence安装目录下的server.xml中加一段邮件服务器的配置,加在confluence的Context中 <Context path=&q ...
- ucloud自动创建instance
用terrform for ucloud: https://www.terraform.io/docs/providers/ucloud/index.html https://docs.ucloud. ...
- RSA/RSA2 进行签名和验签
package com.byttersoft.hibernate.erp.szmy.util; import java.io.ByteArrayInputStream; import java.io. ...
- for循环语句的用法
1.for(int i : index){}用法[又称是foreach用法]: 比如: public class Test { public static void main(String[] arg ...