codeforces gym 100187M Heaviside Function
//大概就是没想起来怎么做
解法:首先观察seitan方程,发现我们要找的是满足seitan(si*x-ai)=1的方程数,即si*x-ai>=0的方程数,因为si=1 or -1,于是分类讨论,当si=1时相当于给定每个x求满足ai<=x的ai数,当si=-1时相当于给定每个x求ai<=-1的方程数,于是我们把si=1和si=-1时的系数ai分别用两个数组记录下来,然后排序,用upper_bound分别求出两种情况下的解,加起来就是答案
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #include<stack> 11 #include<string> 12 #define LL long long 13 14 using namespace std; 15 16 int n,m; 17 int t1=0,t2=0; 18 int f1[200001],f2[200001]; 19 20 int main(){ 21 scanf("%d",&n); 22 for (int i=0;i<n;i++){ 23 int x,y; 24 scanf("%d%d",&x,&y); 25 if (x==1) 26 f1[t1++]=y; 27 else 28 f2[t2++]=y; 29 } 30 sort(f1,f1+t1); 31 sort(f2,f2+t2); 32 scanf("%d",&m); 33 for (int i=0;i<m;i++){ 34 int x; 35 scanf("%d",&x); 36 int ans1=upper_bound(f1,f1+t1,x)-f1; 37 int ans2=upper_bound(f2,f2+t2,-x)-f2; 38 printf("%d\n",ans1+ans2); 39 } 40 return 0; 41 } 42 /* 43 6 44 1 3 45 -1 2 46 1 9 47 -1 2 48 1 7 49 -1 2 50 8 51 0 12 2 8 4 -3 7 9 52 */
View Code
转载于:https://www.cnblogs.com/baby-mouse/p/4657753.html
codeforces gym 100187M Heaviside Function相关推荐
- Codeforces Gym 100187M M. Heaviside Function two pointer
M. Heaviside Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/ ...
- Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks
Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...
- Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)
Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...
- [Codeforces Gym 101651/100725B] Banal Tickets
Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100269 Dwarf Tower (最短路)
题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...
- Codeforces Gym 100676G Training Camp 状压dp
http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
最新文章
- 类加载器的分类及关系
- SAP MM 预留单据的历史修改记录?
- Java集合框架中Map接口的使用
- Visual Studio系统通用快捷键
- 使用Jedis出现Connection refused的解决方案
- docker安装ubuntu镜像
- Android App性能自动化评测方法
- Linux Kernel 2.4 Internals
- CCIE学习(4)——VLAN基础
- Jquery实现图片的预加载与延时加载
- 迈达斯GTS-NX网格模型(FPN)导入Flac3D 6.0
- VS2013及MFC下载
- mysql跨库关联查询(dblink)
- MacBook Air开启CPU虚拟化支持(Windows10)
- 【软件测试】公司招个测试员,我又面试了100多人,结局......
- mysql数据库中学分的简写_一些数据库相关词汇缩写
- nginx本地服务器的搭建(保姆式教学)
- 思科2960恢复系统
- 豆瓣电影数据排名获取
- 玩转人工智能中的机器学习之精品课程
热门文章
- 用python写聊天机器人_用Python 写一个机器人陪你聊天(文尾有彩蛋)
- html5多个图片位置_图表分析中的HTML5地图需求,这款BI轻松5步就给解决了
- ggplot2作图详解:主题(theme)设置
- jenkins java jar_Jenkins 安装和配置、启动jar包
- docker使用_Docker的基本使用
- 系统学习数字图像处理之描绘子
- 各种安装教程---(自用)
- c语言如何直接获得键盘反应,c语言获得键盘的按键
- 双机热备_配置BAS叠加NAT双机热备示例
- 代理模式的原理解析入门