Bestcoder #80

首先吐槽一下,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

Bestcoder #80的相关文章

专业理财网站,年化收益12%以上 承诺100%保本息

http://gz.58.com/jdyd/jh_%E3%80%90%E5%A4%A9%E6%B4%A5%E6%89%BE%E3%80%90%E7%BE%8E%E5%A5%B3%E3%80%91%E4%B8%8A%E9%97%A8%E5%85%A8%E5%A5%97%E5%8C%85%E5%A4%9C%E6%8C%89%E6%91%A9%E6%9C%8D%E5%8A%A1%E3%80%91187-2119-2031/ http://gz.58.com/jdyd/jh_%E3%80%90%E5%A

昆明的

http://www.wasu.cn/search/show/k/%20%E5%B4%87%E5%B7%A6%E5%82%AC%E6%83%85%E8%8D%AF%E6%80%8E%E4%B9%88%E6%89%8D%E8%83%BD%E4%B9%B0%E7%9A%84%E5%88%B0Q%EF%BC%9A%EF%BC%91%EF%BC%91%EF%BC%92%EF%BC%97%EF%BC%94%EF%BC%90%EF%BC%91%EF%BC%91%EF%BC%97%EF%BC%95 http:

apache kafka监控系列-KafkaOffsetMonitor

概览 最近kafka server消息服务上线了,基于jmx指标参数也写到zabbix中了,但总觉得缺少点什么东西,可视化可操作的界面.zabbix中数据比较分散,不能集中看整个集群情况.或者一个cluster中broker列表,自己写web-console比较耗时耗力,用原型工具画了一些管理界面东西,关键自己也不前端方面技术,这方面比较薄弱.这不开源社区提供了kafka的web管理平台KafkaOffsetMonitor.就迅速拿过来运行.大家不要着急,马上娓娓道来. 说明: 这个应用程序来实

thytjsytjytjhyth

http://www.pinterest.com/0xiz27a/%E5%93%AA%E9%87%8C%E6%9C%89%E6%B3%89%E5%B7%9Esm%E4%B8%9D%E8%B6%B3%E4%BC%9A%E6%89%80 http://www.pinterest.com/0xiz27a/%E5%BB%BA%E7%93%AF%E5%93%AA%E9%87%8C%E6%9C%89sm%E4%BC%9A%E6%89%80 http://www.pinterest.com/0xiz27a/%

HDU 5666 Segment——BestCoder Round #80

Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Silen August does not like to talk with others.She like to find some interesting probl

Bestcoder Round# 80

[1003 Sequence] 指数循环节,注意a mod p = 0的情况.此时你的循环节如果返回0,这时你会输出1,而实际上应该是0 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; typedef long long ll; ll n, a, b, c, p; struct Matrix{ ll a[3][

BestCoder Round #80 1004 hdu 5668 中国剩余定理(m不互质版)

链接:戳这里 Circle Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 65536/65536 K (Java/Others) 问题描述 \ \ \ \     Fye对约瑟夫游戏十分着迷. \ \ \ \     她找到了n个同学,把他们围成一个圈,让他们做约瑟夫游戏,然后她得到了一个同学们出圈的编号序列.游戏是这样进行的:以同学1为起点,开始计数,计数到第k个同学,该同学出圈.出圈的同学将不参与之后的计数. \ \ \ \  

BestCoder Round #80 待填坑

Lucky Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1443    Accepted Submission(s): 767 Problem Description Chaos August likes to study the lucky numbers. For a set of numbers S,we set the min

hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7    Accepted Submission(s): 4 Problem Description Hanamichi is taking part in