hdu 4533 威威猫系列故事——晒被子
2013-05-30 23:41
260 查看
看了网上各大神的解题,才发现不进行数学推导怎么都会超时。。。
选了个最简单粗暴的算法,对每个四边形的四个点(x,y),若max(x, y) <= t,则加上(t,t)与(x,y)组成的矩形,否则减去,最后通过合并系数来简化求值操作。。。
选了个最简单粗暴的算法,对每个四边形的四个点(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 威威猫系列故事——晒被子
- hdu 4533 威威猫系列故事——晒被子(两种方法)
- HDU 4533 威威猫系列故事――晒被子(线段树区间更新+分情况推公式)
- hdu 4533 威威猫系列故事——晒被子(线段树 成端更新)
- HDU 4533 威威猫系列故事——晒被子
- HDU 4533 威威猫系列故事——晒被子
- hdu 4533 威威猫系列故事——晒被子(成段更新)
- Hdu 4533 威威猫系列故事——晒被子
- HDOJ 4533 威威猫系列故事——晒被子
- HDU-4525 威威猫系列故事——吃鸡腿
- HDU 威威猫系列故事——篮球梦
- hdu 4523 威威猫系列故事——过生日
- HDU-4504 威威猫系列故事——篮球梦