hdu 4533 威威猫系列故事——晒被子
来源:互联网 发布:国际聊天软件 编辑:程序博客网 时间:2024/04/30 01:29
看了网上各大神的解题,才发现不进行数学推导怎么都会超时。。。
选了个最简单粗暴的算法,对每个四边形的四个点(x,y),若max(x, y) <= t,则加上(t,t)与(x,y)组成的矩形,否则减去,最后通过合并系数来简化求值操作。。。
#include<stdio.h>#include<algorithm>using namespace std;typedef __int64 ll;const int MAX = 50005;struct node{ ll x, y; int maxnum; void getmx() { maxnum = x>y?x:y; }}data1[MAX], data2[MAX];int num1, num2;bool cmp(node &a, node &b){ return a.maxnum < b.maxnum;}int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif int t, n, x; int i; ll j; scanf("%d", &t); while (t--) { scanf("%d", &n); num1 = num2 = 0; node tpNode1, tpNode2; for (i = 0; i< n; i++) { scanf("%I64d%I64d%I64d%I64d", &tpNode1.x, &tpNode1.y, &tpNode2.x, &tpNode2.y); tpNode1.getmx(); tpNode2.getmx(); data1[num1++] = tpNode1; data1[num1++] = tpNode2; j = tpNode1.y; tpNode1.y = tpNode2.y; tpNode2.y = j; tpNode1.getmx(); tpNode2.getmx(); data2[num2++] = tpNode1; data2[num2++] = tpNode2; } sort(data1, data1+num1, cmp); sort(data2, data2+num2, cmp); int bg1 = 0, bg2 = 0; ll now; ll res = 0; ll aa = 0, bb = 0, tt = 0; scanf("%d", &x); while (x--) { scanf("%I64d", &now); for (; data1[bg1].maxnum <= now && bg1 <= num1; bg1++) { aa -= data1[bg1].x+data1[bg1].y; bb += data1[bg1].x*data1[bg1].y; tt++; } for ( ; data2[bg2].maxnum <= now && bg2 <= num2; bg2++) { aa += data2[bg2].x+data2[bg2].y; bb -= data2[bg2].x*data2[bg2].y; tt--; } res = tt*now*now+aa*now+bb; printf("%I64d\n", res); } } return 0;}
- HDU 4533 威威猫系列故事——晒被子
- Hdu 4533 威威猫系列故事——晒被子
- hdu 4533 威威猫系列故事——晒被子
- hdu 4533 威威猫系列故事——晒被子
- 威威猫系列故事——晒被子
- hdu 4533 威威猫系列故事——晒被子(两种方法)
- hdu 4533 威威猫系列故事——晒被子(成段更新)
- hdu 4533 威威猫系列故事——晒被子(线段树 成端更新)
- HDU-4533:威威猫系列故事——晒被子(线段树延迟更新+推公式)
- HDOJ 4533 威威猫系列故事——晒被子
- hdu-4533-威威猫系列故事――晒被子----
- hdu4533-威威猫系列故事——晒被子
- hdu4533 威威猫系列故事——晒被子
- HDU 4533 威威猫系列故事――晒被子 (线段树)
- hdu 4533 威威猫系列故事――晒被子(二重等差数列+差分前缀和)
- hud 2013腾讯编程马拉松 威威猫系列故事——晒被子
- HDU 4533 威威猫系列故事――晒被子(线段树区间更新+分情况推公式)
- HDU4533 威威猫系列故事――晒被子
- 作为一个MYSQL DBA需要了解的知识
- FTP无法连接解决办法
- Android 动画详解之Tween动画
- 《Expert MySQL》翻译——chapter2.解剖数据库系统(2)
- JVM垃圾回收机制
- hdu 4533 威威猫系列故事——晒被子
- 第八章 波形发生电路(自激振荡电路)
- inittab脚本启动解析
- JVM优化
- Linux Inittab
- Factory Method-----工厂方法模式
- 李力游:4G为人们带来更加美好的未来
- CDH4.2的HA配置
- TopCoder 250 points 6-SRM 146 DIV 2 162.67/250 65.07%