刷题记录:
题目1及代码如下:
/*Problem Description
有一天,一个人给了Lisp一颗糖,Lisp嫌自己的糖太少了,于是他去学了两种魔法:
①使得糖果数加1。
②使糖果分裂(即糖果总数乘2)
Lisp想知道,他最少需要使用多少次魔法才能得到他想要的糖果数n。
Input
每个测试点包含多组测试数据。
第一行一个正整数T( 1≤T≤1e5),表示数据组数。
接下来共 T 行,每行一个正整数 n(1≤n≤1e18),含义见题目描述。
Output
共 T 行,每行一个非负整数,表示使糖果数量刚好等于 n 的最少魔法使用次数,行末换行。
Sample Input
4
1
2
5
100000000
Sample Output
0
1
3
37*/
#include<stdio.h>
int main()
{
long long n,m,cnt=0,i;
while(~scanf("%lld",&n)){
for(i=0;i<n;i++){
scanf("%lld",&m);
while(m!=1){
if(m%2==0){
m/=2;
cnt++;
}else{
m-=1;
cnt++;
}
}
printf("%lld\n",cnt);
cnt=0;
}
}
return 0;
}
题目2及代码如下:
/*calm的数学题
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/4096K (Java/Other)
Total Submission(s) : 11 Accepted Submission(s) : 0
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
这儿有一道数学题是关于 Fibonacci数的, Fibonacci数通常是用 Fibonacci数列来表示的,从第三项开始,数列的第n项由第n-1项和第n-2项相加而来。
f1=1,f2=1,fi=fi?1+fi?2(i≥3)
现在给你一个n,calm学长要你求下面这个式子:
∑i=1n∑j=1nh(fi,fj)
如果 x*y 为偶数,则h(x,y)的值为1,否则为0。
Input
多组输入,每组输入仅有一个数字n,1≤n≤109
Output
对于每一组输入,输出上述数学表达式的值,行末换行。
Sample Input
1
2
3
Sample Output
0
0
5*/
#include<stdio.h>
int main()
{
long long n,m;
while(~scanf("%lld",&n)){
m=n*n-(n-n/3)*(n-n/3);
printf("%lld\n",m);
}
return 0;
}
题目3及代码如下:
/*发现内鬼
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一个长度为n的数组,众所周知,在这个数组中除了一个数字外其他的数字都相同(例如,在数组[1,2,1,1]中,除了第二个数字外其他数都相同)。输出与其他数字不相同的数字的下标。数组中的数字下标从1开始编号。
Input
多组输入
第一行一个整数n(3≤n≤1e3),表示数组中数字的个数。
第二行输入n个整数a1,a2,...an(1≤ai≤1e3)
保证a数组中除一个数外的其他数字都相同。
Output
输出与其他元素不同的数字的下标,行末换行。
Sample Input
4
11 13 11 11
5
1 4 4 4 4
Sample Output
2
1*/
#include<stdio.h>
int main()
{
int n,i;
while(~scanf("%d",&n)){
int a[n+2];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
a[n]=a[0];
a[n+1]=a[1];
for(i=-1;i<n-1;i++){
if(i==-1){
if(a[n-1]!=a[i+1]&&a[i+1]!=a[i+2]){
printf("%d\n",i+2);
}
}else if(a[i]!=a[i+1]&&a[i+1]!=a[i+2]){
printf("%d\n",i+2);
}
}
}
return 0;
}