你最愿意做的哪件事,才是你的天赋所在

0%

题目链接

2019年安徽大学ACM/ICPC实验室新生赛(公开赛)

A,B,C

D

思路

判断gcd(a,b)是否为1,为1输出a*b,否则则无解。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll g=gcd(a,b);
if(g!=1)
{
printf("-1\n");
continue;
}
printf("%lld %lld %lld\n",b,a,1ll*a*b);
}
}
阅读全文 »

题面

思路

这道题显示是要求前缀和,观察一下1-8的排列,显然发现如果一个数$a_i=p^k$也就是仅有一个素因子,那么响应的因子肯定会在这里有一个断点也就是会加一

我们看当n=8时

n=2 时 有2:1 ans=2*1=2

n=3 时 有2:1+1 3:1 ans = 2*2+3

n=4 时 有2:1+1+2 3:1 4:1 ans = 4*2+3+4

阅读全文 »

Pick定理内容

设二维平面上只有整数点,多边形的面积为S,多边形包含的点个个数为a,多边形边上的点的个数为b,则有以下等式

Pro:证明过程

Pick定理的扩展-Farey序列

Fatey序列是指那些0-1之间且分母不超过n的分数从小到大,例如

阅读全文 »

极坐标

二维平面内,除了根据坐标可以确定一个点之外,通过一个定义好的极角和一个长度也可以确定一个唯一的点。

可以得到

阅读全文 »

两直线交点

首先我们知道两点能够确定一条直线,能够得到直线的方程

假设现在有两条直线

联立两个方程就可以得到一个简答的答案

阅读全文 »

题目链接

HDU 6242

思路

因为题目保证有答案,所以我们可以随机出三个点,然后判断,可以证明复杂度是够的,然后三点确定一个圆,求圆心的方法这篇博客很清楚了。
坑点就是千万别把1放在printf的参数中,spj会判断错误(我也不知道为什么)。
三点求圆心

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const double eps = 1e-6;
int n;
double R;
struct node
{
double x;
double y;
}p[N],ans;
node solve(node a, node b, node c)
{
double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
double d = a1*b2 - a2*b1;
if(d<eps) return {1e18,1e18};
return {a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d};
}
void printf(double x,double y,double r)
{
printf("%.6f %.6f %.6f\n",x,y,r);
}
bool same(double x,double y)
{
return fabs(x-y)<eps;
}
double dis(node a, node b)
{
return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
}
void work()
{
int need = (n+1)/ 2;
while (true)
{
int i =rand() % n;
int j =rand() % n;
int k =rand() % n;
node point = solve(p[i], p[j], p[k]);
if(abs(point.x)>1e9||abs(point.y)>1e9) continue;
double r = dis(point, p[i]);
int num = 0;
for ( i = 0; i < n; i++)
{
if (same(dis(p[i],point),r))num++;
if (num == need) {
printf("%.6f %.6f %.6f\n", point.x, point.y, r);
return;
}
}
}
}
void sol()
{

scanf("%d", &n);
for (int i = 0; i < n; i++)
{
double x,y;
scanf("%lf %lf", &x, &y);
p[i]={x,y};
}
double one = 1;
if(n==1)
printf("%.6f %.6f %.6f\n",p[0].x+1,p[0].y,one);
else if(n>=5)
work();
else
printf("%.6f %.6f %.6f\n",(p[0].x+p[1].x)/2,(p[0].y+p[1].y)/2,dis(p[0],p[1])/2);

}
int main()
{
srand(time(0));
int t;
scanf("%d", &t);
while (t--)sol();
}

Spring Bean 定义

Bean定义

bean是一个被实例化,组装并通过Spring IoC容器管理的对象
bean定义包含成为配置元数据的信息。需要明白以下问题

  1. 如何创建一个bean
  2. bean的声明周期详细信息
  3. bean的依赖关系
属性 描述
class 这个属性强制性,并且指定用来创建bean类
name 这个属性是bean的标识符,就是这个bean的名字,可以使用ID或者name属性来指定标识符
scope 这个属性是bean创建对象的作用域
constructor-arg 用来注入依赖关系
properties 用来注入依赖关系
autowiring mode 用来注入依赖关系
lazy-initialization mode 延迟初始化bean,告诉IoC容器在它第一次被请求时,而不是在启动时去创建一个bean实例。
destruction方法 回调方法,当bean的容器被销毁时,使用回调方法
阅读全文 »

用Spring写一个HelloWorld

环境

  1. jdk 1.7
  2. eclipse 2017
  3. spring 4.2.5
  4. common-logging 1.2

    创建项目

    创建eclipse文件,导入必要的jar包
    image.png

    编写程序

    编写HelloWorld与xml文件以及MainAPP文件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    //HelloWorld.java
    package cn.suock.spring;
    public class HelloWorld {
    private String message;
    public void setMessage(String message){
    this.message = message;
    }
    public void getMessage(){
    System.out.println("Your Message : " + message);
    }
    }
阅读全文 »

题目链接

Training #10

F

思路

这道题就是打表找规律,然后发现满足的式子是f[1]=4,f[2]=14,f[n]=4*f[n-1]-f[n-2];
得到这个式子之后考虑大数的问题,看到大数直接上java就好了。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
int T;
Scanner in = new Scanner(System.in);
T=in.nextInt();
BigInteger[] num = new BigInteger[150];
num[0]=BigInteger.valueOf(4);
num[1]=BigInteger.valueOf(4);
num[2]=BigInteger.valueOf(14);
for(int i=3;i<150;i++)
{
num[i]=num[i-1].multiply(BigInteger.valueOf(4));
num[i]=num[i].subtract(num[i-2]);
}
while(T-->0)
{
BigInteger n = in.nextBigInteger();
for(int i=0;i<150;i++)
{
if(n.compareTo(num[i])!=1)
{
System.out.println(num[i]);
break;
}
}
}
}

}
阅读全文 »

Palindromes

题目链接

Palindromes

思路

要求就是求第k大的回文数,k很大,我们考虑二分。
首先二分出位数,然后减去后再减去一,然后把第一位加上1再反转过来就是答案。细节很多,值得注意。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
string dezero(string a)//用来去掉正数前面的0,也就是说可以输入000001类似这样的数字
{
long int i;
for(i=0;i<a.length();i++)
{
if(a.at(i)>48) break;
}
if(i==a.length()) return "0";
a.erase(0,i);
return a;
}
int judge(string a,string b)//判断两个正数的大小
{
if(a.length()>b.length()) return 1;
if(a.length()<b.length()) return -1;
long int i;
for(i=0;i<a.length();i++)
{
if(a.at(i)>b.at(i)) return 1;
if(a.at(i)<b.at(i)) return -1;
}
return 0;
}
string sub(string a,string b)//自然数减法
{
a=dezero(a);
b=dezero(b);
long int i,j=0;
string c="0";
string c1,c2;
string d="-";
if(judge(a,b)==0) return c;
if(judge(a,b)==1)
{
c1=a;
c2=b;
}
if(judge(a,b)==-1)
{
c1=b;
c2=a;
j=-1;
}
reverse(c1.begin(),c1.end());
reverse(c2.begin(),c2.end());
for(i=0;i<c2.length();i++)
{
if(c2.at(i)>=48&&c2.at(i)<=57) c2.at(i)-=48;
if(c2.at(i)>=97&&c2.at(i)<=122) c2.at(i)-=87;
}
for(i=0;i<c1.length();i++)
{
if(c1.at(i)>=48&&c1.at(i)<=57) c1.at(i)-=48;
if(c1.at(i)>=97&&c1.at(i)<=122) c1.at(i)-=87;
}
for(i=0;i<c2.length();i++)
{
c1.at(i)=c1.at(i)-c2.at(i);
}
for(i=0;i<c1.length()-1;i++)
{
if(c1.at(i)<0)
{
c1.at(i)+=10;
c1.at(i+1)--;
}
}
for(i=c1.length()-1;i>=0;i--)
{
if(c1.at(i)>0) break;
}
c1.erase(i+1,c1.length());
for(i=0;i<c1.length();i++)
{
if(c1.at(i)>=10) c1.at(i)+=87;
if(c1.at(i)<10) c1.at(i)+=48;
}
reverse(c1.begin(),c1.end());
if(j==-1) c1.insert(0,d);
return c1;
}
int main()
{
int t;
cin>>t;
while(t--)
{
string k;
cin>>k;
if(judge(k,"1")==0)
{
cout<<"0"<<endl;
continue;
}
int l=0,r=10000000;
int ans=0;
while(l<r-1)
{
string s;
int mid = (l+r)>>1;
s=string((mid+1)/2+1,'9');
if(mid%2==1)
{
s[1]='0';
}
s[0]='1';
if(mid==0)s="0";
if(judge(k,s)==1)l=mid;
else r=mid;
}
ans=l;
string s=string((ans+1)/2+1,'9');
if(ans%2==1)
{
s[1]='0';
}
s[0]='1';
k=sub(k,s);
k=sub(k,"1");
int tans =ans+1;
ans=(ans+2)/2;
while(k.size()<ans)
{
k.insert(k.begin(),'0');
}
k[0]+=1;
string k1 = k;
reverse(k.begin(),k.end());
ans++;
if(tans<=1)
{
cout<<k<<endl;
continue;
}
if(tans%2==0)k1+=k;
else
{
k.erase(k.begin());
k1+=k;
}
cout<<k1<<endl;
}
}
阅读全文 »