上一页 1 2 3 4 5 6 7 ··· 9 下一页
摘要: 题目:Sum原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704分析:实际上就是求2^(n-1)mod(1e9+7).因为2与1e9+7互素,所以可以用费马小定理。参考:http://baike.baidu.com/view/263807.htm(a,p)=1,则a^(p-1)Ξ1(modp).可得:2^(n-1)%mod=2^((n-1)%(mod-1)) %mod;证明:(n-1)=(n-1)%mod+k*(mod-1).则:2^(n-1)=2^((n-1)%(mod-1)) * 2^(k*(mod-1));可知结论成立。 1 #inclu 阅读全文
posted @ 2013-09-15 21:57 EtheGreat 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 题目:Good Numbers原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722分析:找规律,每十个数中有一个。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define maxn 100005 8 #define LL __int64 9 int main()10 {11 int T,cas=1;12 cin>>T;13 LL l,r;14 while(T--)15 {16 ... 阅读全文
posted @ 2013-09-15 20:55 EtheGreat 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 题目:Minimum palindrome原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4731分析:找规律。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int n,m; 8 9 int main()10 {11 int T,cas=1;12 cin>>T;13 while(T--)14 {15 scanf("%d%d",&m,&n);16 printf("Case... 阅读全文
posted @ 2013-09-15 20:35 EtheGreat 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 原题链接:分析:求最小周期的应用。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1005 6 using namespace std; 7 char s[maxn]; 8 int next[maxn],len; 9 void get_next()10 {11 int i=0,j=-1;len=strlen(s);12 next[0]=-1;13 while(i<len)14 {15 if(j==-1||s[i]==s[j]){16 i++,j++;1... 阅读全文
posted @ 2013-09-08 19:21 EtheGreat 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1655分析:注意可能会反向。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1005 7 #define inf 0x7fffffff 8 using namespace std; 9 int l[maxn],r[maxn];10 int dis1[maxn];//clockwise11 int dis2[maxn];//ante-clockwise12 int ans[maxn];13 int main()1 阅读全文
posted @ 2013-09-08 18:40 EtheGreat 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 一:埃拉托斯尼斯筛法. 1 #define maxn 1000000 2 bool isPrime[maxn+10]={true}; 3 int prime[maxn],k=0; 4 void selPrime() 5 { 6 isPrime[0]=isPrime[1]=false; 7 for(int i=2;i<=maxn;i++) 8 { 9 if(isPrime[i])10 {11 prime[k++]=i;12 ... 阅读全文
posted @ 2013-09-05 10:10 EtheGreat 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=117分析:设数为N,则其位数为(int)lg(N)+1;log(10)=ln(10);素数定理:令Pn表示 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int main() 8 { 9 int n;10 double e=2.71828;11 while(cin>>n)12 {13 double ans=double(n... 阅读全文
posted @ 2013-09-04 23:39 EtheGreat 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1300分析:dp,最长公共上升子列。对于两个序列num1[maxn],num2[maxn]:如果num1[i]==num2[j],dp[i][j]=max(dp[i][k])+1;(knum2[k]).否则dp[i][j]=dp[i-1][j]. 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1005 6 using namespace std; 7 int n1,n2,ans; 8 int num1[maxn],num2[maxn 阅读全文
posted @ 2013-09-02 17:42 EtheGreat 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1730分析:线段树单点更新,区间求和。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 500005 7 #define mod 1000007 8 using namespace std; 9 int sum[maxn>1;19 build(l,m,rt>1;30 if(ii>1;38 int res=0;39 if(L=m+1)res^=get_sum(L,R,m+1,r,rt... 阅读全文
posted @ 2013-08-31 15:52 EtheGreat 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1727分析:用 l[i] 记录第 i 层楼有多少物品需要往上继续搬运,如果某层楼没有物品,但是更上面还有,则仍需要往上走,所以需要+1. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 111 7 #define mod 1000007 8 using namespace std; 9 int l[maxn];10 int main()11 {12 int n,cas=1,s,t,rig;13 w... 阅读全文
posted @ 2013-08-31 15:13 EtheGreat 阅读(142) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 9 下一页