2015 Hdu 多校赛第五场

Hdu 5344 MZL’s xor

链接

MZL’s xor

题意

给定n,m,z,l
$A_1=0,A_i=(A_{i−1}*m+z) \% l$
$求所有的 (A_i+A_j)(1≤i,j≤n) 异或的值$
如n=2 所求为:(A1+A1)^(A1+A2)^(A2+(A1)^(A2+A2)

分析

因为x^x=0,x^0=x,即(Ai+Aj)^(Aj+Ai)=0
对于任何$i \neq j$ 都存在(Ai+Aj)和(Aj+Ai),它们异或后为0
消掉异或后为0的项只剩 (Ai+Aj) (i=j,1≤i,j≤n)
即求 (A1+A1)^(A2+A2)^…^(An+An)

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
const int N=500000;
long long a[N+10];
int main()
{

int T,n,m,z,l;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&n,&m,&z,&l);
a[1]=0;
long long ans=0;
for(int i=2;i<=n;i++){
a[i]=(a[i-1]*m+z)%l;
ans^=2*a[i];
}
printf("%I64d\n",ans);
}
return 0;
}

Hdu 5347 MZL’s chemistry

链接

MZL’s chemistry

题意

给定两个化学元素的原子序数,比较它们的第一电离能的大小

分析

纯属化学题,没有任何意义…
元素周期表中:
同一主族元素从上到下第一电离能逐渐增大
同一周期从左到右第一电离能呈增大趋势,
但是第二主族和第五主族为特例
即同周期第二主族比三主族小,第五主族比六主族小
打表存每个元素所在的主族和周期,根据规律比较即可

代码

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
#include<stdio.h>
const int N=100;
struct stu{
int pre,gro;
}a[N];
void init()
{

a[1].pre=1,a[1].gro=1;
a[2].pre=1,a[2].gro=8;
int pre=2,gro=1;
for(int i=3;i<=18;i++){
a[i].pre=pre;
a[i].gro=gro++;
if(i==10){
pre++;
gro=1;
}
}
//35,36,53,54,85,86
a[35].pre=4,a[35].gro=7;
a[36].pre=4,a[36].gro=8;
a[53].pre=5,a[53].gro=7;
a[54].pre=5,a[54].gro=8;
a[85].pre=6,a[85].gro=7;
a[86].pre=6,a[86].gro=8;
}
bool judge(int x,int y)
{

if(a[x].gro==a[y].gro)
return a[x].pre<a[y].pre?true:false;
if((a[x].gro==2&&a[y].gro==3)||(a[x].gro==5&&a[y].gro==6))
return true;
else if((a[x].gro==3&&a[y].gro==2)||(a[x].gro==6&&a[y].gro==5))
return false;
return a[x].gro>a[y].gro?true:false;
}
int main()
{

int u,v;
init();
while(scanf("%d%d",&u,&v)!=EOF){
if(judge(u,v))
printf("FIRST BIGGER\n");
else
printf("SECOND BIGGER\n");
}
return 0;
}

Hdu 5349 MZL’s simple problem

链接

MZL’s simple problem

题意

有一个集合,初始为空,要对其进行n次操作,操作有三种
1 x : 把x加到集合
2 : 若集合非空,删除集合的最小值
3 : 输出集合的最大值,若集合为空输出0

分析

用两个变量来记录集合的元素个数和最大值
当集合为空,最大值为无穷小

代码

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
#include<stdio.h>
const int INF=1000000007;
#define max(a,b) a>b?a:b
int main()
{

int n,ans=-INF,len=0;
scanf("%d",&n);
while(n--){
int ope,x;
scanf("%d",&ope);
if(ope==1){
scanf("%d",&x);
ans=max(ans,x);
len++;
}
else if(ope==2){
len=(len==0?0:len-1);
if(len==0)
ans=-INF;
}
else{
if(ans==-INF)
printf("0\n");
else
printf("%d\n",ans);
}
}
return 0;
}