Bestcoder #80
首先吐槽一下,ca爷出的这套题到处都是坑,bestcoder变成besthack,Ranting已经掉得不能看了
A题:
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5665
分析:这题题目写错,一wa,最后发现是求的非负数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
long long a[maxn];
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
int flag=,flag1=;
for(int i=;i<n;i++)
{
if(a[i]==)
{
flag=;
}else if(a[i]==)
{
flag1=;
}
}
if(flag&&flag1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
B题:
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5666
分析:因为p是质数,所以内部线段上不可能有点,直接皮克定理,取模3A
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct point{
long long x,y;
}p[],m[];
long long gcd(long long a,long long b){
long long c;
while(b){
c=a%b;
a=b;
b=c;
}
return a;
}
long long S(point p1,point p2,point p0){
return abs((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x));
}
int main(){
long long sum,s,ans;
int t;
long long h,q;
cin>>t;
while(t--){
cin>>h>>q;
p[].x=,p[].y=;
p[].x=h,p[].y=;
p[].x=,p[].y=h;
m[].x=abs(p[].x-p[].x);m[].y=abs(p[].y-p[].y);
m[].x=abs(p[].x-p[].x);m[].y=abs(p[].y-p[].y);
m[].x=abs(p[].x-p[].x);m[].y=abs(p[].y-p[].y);
sum=gcd(m[].x,m[].y)+gcd(m[].x,m[].y)+gcd(m[].x,m[].y);
s=S(p[],p[],p[]);
ans=(s-sum+)/%q;
cout<<ans<<endl;
}
return ;
}
然而事实证明了,这个题目会被hack,因为会爆long long,赛后java写了个大数类才过的,皮克定理最后推出公式是(q-1)*(q-2)/2
import java.math.BigInteger;
import java.util.Scanner; public class Main { @SuppressWarnings("resource")
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int t;
t=cin.nextInt();
for(int i=0;i<t;i++){
BigInteger p,q,sum1,sum2;
p=cin.nextBigInteger();
q=cin.nextBigInteger();
sum1=p.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(2));
sum2=p.subtract(BigInteger.valueOf(2));
System.out.println(sum1.multiply(sum2).mod(q));
}
} }
Accept
Bestcoder #80的更多相关文章
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- BestCoder Round #80 1002
HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...
- Bestcoder Round# 80
[1003 Sequence] 指数循环节,注意a mod p = 0的情况.此时你的循环节如果返回0,这时你会输出1,而实际上应该是0 #include <algorithm> #inc ...
- hdu5666 BestCoder Round #80
Segment Accepts: 418 Submissions: 2020 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- BestCoder Round #80 待填坑
Lucky Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- hdoj5667 BestCoder Round #80 【费马小定理(膜拜)+矩阵快速幂+快速幂】
#include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
- hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Ot ...
随机推荐
- JPA 系列教程8-双向一对一共享主键
双向一对一共享主键的ddl语句 CREATE TABLE `t_person` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(25 ...
- JAVA面向对象3---多态
1. 多态:父类或者接口的引用 指向了子类对象. 多态的好处:提高了代码的扩展性 多态的弊端:父类不能调用子类的特有的内容. 多态的前提: 1.要有关系,继承或实现 2.要有覆盖(重写),因为父类不 ...
- a:link visited hover active
CSS中a:link.a:visited.a:hover.a:active的用法:建议:尽可能的手写代码,可以有效的提高学习效率和深度.在网页设计中,设计美观的超链接效果可以增强网站的用户体验,可能会 ...
- JS-运动基础(一)续
2.淡入淡出的图片 用变量存储透明度 <title>无标题文档</title> <style> #div1{width:293px; height:220px; b ...
- 浅谈C# 多态的魅力(虚方法,抽象,接口实现)
前言:我们都知道面向对象的三大特性:封装,继承,多态.封装和继承对于初学者而言比较好理解,但要理解多态,尤其是深入理解,初学者往往存在有很多困惑,为什么这样就可以?有时候感觉很不可思议,由此,面向对象 ...
- PAT (天梯)L2-004. 这是二叉搜索树吗?
L2-004. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的 ...
- 转:LR的响应时间与使用IE所感受时间不一致的讨论
在做性能测试时,有时碰到这样一种情况,使用性能工具LR测试出来的响应时间比实际使用IE感受到的时间要长,例如,实际使用IE打开一个系统时只需要1~2秒,而使用LR跑一个用户所得出的结果可能是8秒.10 ...
- windbg 之 如何设置模块加载时断下
这里先介绍两个指令: sx指令: The sx* commands control the action that the debugger takes when an exception occur ...
- .NET 4.0里异常处理的新机制
非原创,转载自: http://www.cnblogs.com/killmyday/archive/2010/09/05/1818533.html .NET里不能捕捉(catch)到一些异常了,而 ...
- Windows 2003】利用域&&组策略自动部署软件
Windows 2003]利用域&&组策略自动部署软件 转自 http://hi.baidu.com/qu6zhi/item/4c0fa100dc768613cc34ead0 ==== ...