首页 技术 正文
技术 2022年11月18日
0 收藏 839 点赞 4,651 浏览 2002 个字

Pupu

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 913    Accepted Submission(s): 385

Problem DescriptionThere is an island called PiLiPaLa.In the island there is a wild animal living in it, and you can call them PuPu. PuPu is a kind of special animal, infant PuPus play under the sunshine, and adult PuPus hunt near the seaside. They fell happy every day.
But there is a question, when does an infant PuPu become an adult PuPu? Aha, we already said, PuPu is a special animal. There are several skins wraping PuPu’s body, and PuPu’s skins are special also, they have two states, clarity and opacity. The opacity skin will become clarity skin if it absorbs sunlight a whole day, and sunshine can pass through the clarity skin and shine the inside skin; The clarity skin will become opacity, if it absorbs sunlight a whole day, and opacity skin will keep sunshine out.
when an infant PuPu was born, all of its skins were opacity, and since the day that all of a PuPu’s skins has been changed from opacity to clarity, PuPu is an adult PuPu.
For example, a PuPu who has only 3 skins will become an adult PuPu after it born 5 days(What a pity! The little guy will sustain the pressure from life only 5 days old)
Now give you the number of skins belongs to a new-laid PuPu, tell me how many days later it will become an adult PuPu? InputThere are many testcase, each testcase only contains one integer N, the number of skins, process until N equals 0 OutputMaybe an infant PuPu with 20 skins need a million days to become an adult PuPu, so you should output the result mod N Sample Input230 Sample Output12 o(︶︿︶)o 唉,好不容易想到方法的,,,居然超时了, 思路:我们可以将此题用二进制的思想来解题。0代表不透明,1代表透明。2层: (0 0)->(1 0)->(0 1)三天3层:(0 0 0)->(1 0 0)-> (0 1 0)->(1 1 0)->(0 0 1) 五天所以题意就转变为求2的n-1次方%n。可是刚刚开始做的时候超时了,要对2的n-1次方这个步骤进行优化,就过了- -||ps:http://acm.hdu.edu.cn/showproblem.php?pid=3003 

/*超时。。。。呜呜
#include <stdio.h>
int main()
{
__int64 n,m,i,j,a;
while(scanf("%I64d",&n),n)
{
m=n-1;
a=2;
for(i=1;i<m;)
{
if(i*2<=m)
{
a=a*a%n;
i=i*2;
}
else
{
a=a*2%n;
i++;
}
}
printf("%I64d\n",(a+1)%n);
}
return 0;
}*/

优化后的代码。。。

#include<stdio.h>
int main()
{
__int64 n,m,i,k,a,bit[];
while(scanf("%I64d",&n),n)
{
a=;
k=;
m=n-;
while(m)
{
bit[k++]=m%;//判断奇偶
m=m>>;//m/=2;
}
for(i=k-;i>=;i--)
{
a=a*a%n;
if(bit[i]==)
a=a*%n;
}
printf("%d\n",(a+)%n);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893