20ms Ac Code

Rectangle Aread

C Code

#include <stdio.h>

int computeArea(int A,int B,int C,int D,int E,int F,int G,int H){
float ALX = (C-A) ;
float ALY = (D-B) ;
float BLX = (G-E) ;
float BLY = (H-F) ;
float PAX = (float)(C+A) / 2;
float PAY = (float)(D+B) / 2;
float PBX = (float)(G+E) / 2;
float PBY = (float)(H+F) / 2;
float LABX = PAX-PBX>0?PAX-PBX:PBX-PAX;
float LABY = PAY-PBY>0?PAY-PBY:PBY-PAY;
float MAX_X = ALX<BLX?ALX:BLX;
float MAX_Y = ALY<BLY?ALY:BLY;
if( LABX >= (float)((ALX+BLX)/2) || LABY >=(float)((ALY+BLY)/2)) {return ALX*ALY+BLX*BLY;}
else{
if( LABX <= ((ALX>BLX?ALX/2:BLX/2)-2*(ALX>BLX?BLX/2:ALX/2)) && LABY <= ((ALY>BLY?ALY/2:BLY/2)-2*(ALY>BLY?BLY/2:ALY/2))){
return ALX>BLX?ALX*ALY:BLX*BLY;
}
else{
return ALX*ALY+BLX*BLY - ((ALX+BLX)/2-LABX> MAX_X?MAX_X:(ALX+BLX)/2-LABX) * ((ALY+BLY)/2-LABY > MAX_Y?MAX_Y:(ALY+BLY)/2-LABY);
}
}
}

int main(){
int m = computeArea(-2,-2,2,2,-3,-3,3,-1);
printf("%d\n",m);
return 0;
}

时间: 2024-08-21 23:18:06

20ms Ac Code的相关文章

USACO holstein AC code

/* ID:kevin_s1 PROG:holstein LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib&g

hdu oj 4300 Clairewd’s message AC code

#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<vector> #include<cassert> using namespace std; int main(void) { int T; cin >> T; while (T--) { string S, msg; while (cin >> S >> msg) {

【BZOJ 2553】[BeiJing2011]禁忌 AC自动机+期望概率dp

我一开始想的是倒着来,发现太屎,后来想到了一种神奇的方法——我们带着一个既有期望又有概率的矩阵,偶数(2*id)代表期望,奇数(2*id+1)代表概率,初始答案矩阵一列,1的位置为1(起点为0),工具矩阵上如果是直接转移那么就是由i到j概率期望都乘上1/alphabet,特别的,对于一个包含禁忌串的节点直接由其父节点指向0,而且在计算期望是多加上他的概率,最后统计答案时把答案矩阵上所有的期望加和即可,这个方法很完美的被卡精了....... #include <cstdio> #include

【LeetCode】89.Gary Code

Problem: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin w

[C++]LeetCode: 86 Gray Code (格雷码)

题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0

[BJOI2006]狼抓兔子 暴力AC啦!

直接暴力建边,在lougu上跑的飞快.(except the last test) 总结一下也就是三句话: insert(id(i, j), id(i, j + 1), x) insert(id(i, j), id(i + 1, j), x) insert(id(i, j), id(i + 1, j + 1), x) 没了就,..dinic什么的就看看本博客分享的总结爸... 代码当然还是要发的,即使只是一个暴力.. 1 #include <map> 2 #include <set>

(模板)AC自动机模板

1. 给出模式串和文本串,文本串长度小于1e6,模式串长度之和小于1e6,求文本串中有多少模式串出现. 题目链接:https://www.luogu.org/problem/P3808 AC code: /* luoguP3808 (AC自动机模板题) 求文本串中有多少模式串出现 */ #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cstd

HDU 1513 Palindrome:LCS(最长公共子序列)or 记忆化搜索

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意: 给你一个字符串s,你可以在s中的任意位置添加任意字符,问你将s变成一个回文串最少需要添加字符的个数. 题解1(LCS): 很神奇的做法. 先求s和s的反串的LCS,也就是原串中已经满足回文性质的字符个数. 然后要变成回文串的话,只需要为剩下的每个落单的字符,相应地插入一个和它相同的字符即可. 所以答案是:s.size()-LCS(s,rev(s)) 另外,求LCS时只会用到lcs[i-

HDU 4162 Shape Number(字符串,最小表示法)

HDU 4162 题意: 给一个数字串(length <= 300,000),数字由0~7构成,求出一阶差分码,然后输出与该差分码循环同构的最小字典序差分码. 思路: 第一步是将差分码求出:s[i] = (s[i] - s[i+1] + 8) % 8; 第二步是求出最小字典序的循环同构差分码,我之前没注意到字符串规模..直接用set做,MLE+TLE... 正确的方式应该是一种O(n)的解法,即最小表示法.//关于最小表示法的证明与详述请参考最小表示法:) 最小表示法算法: 初始时,i=0,j=