首先吐槽一下,ca爷出的这套题到处都是坑,bestcoder变成besthack,Ranting已经掉得不能看了
A题:
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5665
分析:这题题目写错,一wa,最后发现是求的非负数
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <bitset> 10 #include <cmath> 11 #include <queue> 12 #include <stack> 13 using namespace std; 14 const int maxn=100100; 15 long long a[maxn]; 16 int main() 17 { 18 int t,n; 19 cin>>t; 20 while(t--) 21 { 22 cin>>n; 23 for(int i=0;i<n;i++) 24 cin>>a[i]; 25 int flag=0,flag1=0; 26 for(int i=0;i<n;i++) 27 { 28 if(a[i]==1) 29 { 30 flag=1; 31 }else if(a[i]==0) 32 { 33 flag1=1; 34 } 35 } 36 if(flag&&flag1) cout<<"YES"<<endl; 37 else cout<<"NO"<<endl; 38 } 39 return 0; 40 }
B题:
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5666
分析:因为p是质数,所以内部线段上不可能有点,直接皮克定理,取模3A
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<string> 6 #include<vector> 7 #include<algorithm> 8 using namespace std; 9 struct point{ 10 long long x,y; 11 }p[3],m[3]; 12 long long gcd(long long a,long long b){ 13 long long c; 14 while(b){ 15 c=a%b; 16 a=b; 17 b=c; 18 } 19 return a; 20 } 21 long long S(point p1,point p2,point p0){ 22 return abs((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)); 23 } 24 int main(){ 25 long long sum,s,ans; 26 int t; 27 long long h,q; 28 cin>>t; 29 while(t--){ 30 cin>>h>>q; 31 p[0].x=0,p[0].y=0; 32 p[1].x=h,p[1].y=0; 33 p[2].x=0,p[2].y=h; 34 m[0].x=abs(p[0].x-p[1].x);m[0].y=abs(p[0].y-p[1].y); 35 m[1].x=abs(p[1].x-p[2].x);m[1].y=abs(p[1].y-p[2].y); 36 m[2].x=abs(p[0].x-p[2].x);m[2].y=abs(p[0].y-p[2].y); 37 sum=gcd(m[0].x,m[0].y)+gcd(m[1].x,m[1].y)+gcd(m[2].x,m[2].y); 38 s=S(p[1],p[2],p[0]); 39 ans=(s-sum+2)/2%q; 40 cout<<ans<<endl; 41 } 42 return 0; 43 }
然而事实证明了,这个题目会被hack,因为会爆long long,赛后java写了个大数类才过的,皮克定理最后推出公式是(q-1)*(q-2)/2
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 6 @SuppressWarnings("resource") 7 public static void main(String[] args) { 8 Scanner cin=new Scanner(System.in); 9 int t; 10 t=cin.nextInt(); 11 for(int i=0;i<t;i++){ 12 BigInteger p,q,sum1,sum2; 13 p=cin.nextBigInteger(); 14 q=cin.nextBigInteger(); 15 sum1=p.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(2)); 16 sum2=p.subtract(BigInteger.valueOf(2)); 17 System.out.println(sum1.multiply(sum2).mod(q)); 18 } 19 } 20 21 }
Accept
时间: 2024-10-07 05:06:30