BigNum a, b, c, d;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
char out[60005];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main ()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
char in[50];
int flag;
int n;
int i, j;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
while ( scanf ( "%s%d", &in, &n ) != EOF )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int len = strlen ( in );
flag = 0;
for ( i=0; i<len; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if ( in[i] == '.' )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
flag = ( len - i - 1 ) * n;
for ( j=i+1; j<len; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
in[j-1] = in[j];
}
in[j] = in[j+1];
len --;
break;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
a.set ( "1", 1 );
b.set ( in, len );
c.set ( "0", 1 );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if ( ! Cmp ( b, c ) )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
printf ( "0\n" );
continue;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
while ( n != 0 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if ( n & 1 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
Mul ( a, b, c );
Cpy (a, c);
}
Cpy ( d, b );
Mul ( b, d, c );
Cpy ( b, c );
n >>= 1;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int l;
int count = 0;
int p = 0;
b.set ( "0", 1 );
while ( Cmp ( a, b ) || count <= flag )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
Div ( a, 10, l );
if ( count == flag && flag )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
out[p++] = '.';
}
out[p++] = (char)(l + '0');
count ++;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
out[p] = '\0';
for ( i=0; i<p-1; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if ( out[i] == '0' )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
out[i] = 0;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if ( out[i] == '.' )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
out[i] = 0;
}
break;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if ( p>1 && out[p-1] == '0' )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
p --;
}
for ( i=p-1; out[i]!=0; i-- )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
printf ( "%c", out[i] );
}
printf ( "\n" );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
return 0;
}
摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>const int OneNode = 1000000 ;//一位里不能超过OneNodeconst int NodeLen = 6... 阅读全文
摘要: 这个题目是北大上面深度优先遍历的经典算法,主要的减枝策略是对数组进行排序,在每次搜索时一定要把第一个放进去。地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1011
#include <stdio.h>#include <stdlib.h>int stick[64];int used[... 阅读全文
一个约瑟夫生死游戏的变形,因为K的数目只有14,所以想到打表来求解。地址:
#include < stdio.h >
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) int ans[14] = { 2, 7, 5, 30, 169, 441, 1872, 7632, 1740, 93313, 459901, 1358657, 2504881, 13482720 };
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int k;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
while ( scanf ( "%d", &k ) != EOF && k )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
printf( "%d\n", ans[k-1] );
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
一个NOI题目,求的是一个二元一次不定方程组的整数解,使用扩展欧几里德算法及整数解公式。地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1061
#include <stdio.h>
__int64 x,y;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) __int64 extended_gcd(__int64 a,__int64 b) {
__int64 d,t;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(b==0) {
x=1;
y=0;
return a;
}
d=extended_gcd(b,a%b);
t=x;
x=y;
y=t-(a/b)*y;
return d;
}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) int main() {
__int64 x1,y1,m,n,l,b;
__int64 d,s;
scanf("%I64d%I64d%I64d%I64d%I64d",&x1,&y1,&m,&n,&l);
x1=(x1+l)%l;
y1=(y1+l)%l;
if(m==n)printf("Impossible\n");
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(m>n)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
d=extended_gcd((m-n),l);
b=y1-x1;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
d=extended_gcd((n-m),l);
b=x1-y1;
}
if(b%d!=0)printf("Impossible\n");
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
s=x*(b/d)%l;
while(s<0)
s+=(l/d);
printf("%I64d\n",s);
}
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
动态规划(DP),地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1080
#include <stdio.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) char tab[5] = {'A', 'C', 'G', 'T', '-'};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) int list[5][5] = {5, -1, -2, -1, -3,
-1, 5, -3, -2, -4,
-2, -3, 5, -2, -2,
-1, -2, -2, 5, -1,
-3, -4, -2, -1, 0,
};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int str1[105];
int str2[105];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int dp[105][105];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int find(char ch)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i;
for (i=0; i<5; i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if (tab[i]==ch)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
break;
}
}
return i;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int max(int a, int b, int c)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int m = a;
if (b>m)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
m = b;
}
if (c>m)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
m = c;
}
return m;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int lcs(int s1[], int len1, int s2[], int len2)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int i, j;
for (i=0; i<=len1; i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for (j=0; j<=len2; j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if (i==0 && j==0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dp[i][j] = 0;
}
else if (i==0 && j!=0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dp[i][j] = dp[i][j-1] + list[4][s2[j-1]];
}
else if (i!=0 && j==0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dp[i][j] = dp[i-1][j] + list[s1[i-1]][4];
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dp[i][j] = max(dp[i-1][j-1]+list[s1[i-1]][s2[j-1]], dp[i][j-1]+list[4][s2[j-1]], dp[i-1][j]+list[s1[i-1]][4]);
}
}
}
return dp[i-1][j-1];
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int t, n1, n2;
int i;
char temp[105];
while (scanf("%d", &t) != EOF)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
while (t--)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d%s", &n1, &temp);
for (i=0; i<n1; i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
str1[i] = find(temp[i]);
}
scanf("%d%s", &n2, &temp);
for (i=0; i<n2; i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
str2[i] = find(temp[i]);
}
printf("%d\n", lcs(str1, n1, str2, n2));
}
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
摘要: 动态规划(DP),排序的时候使用的还是我自己写的快速排序,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1088
#include "stdio.h"typedef struct{ int h; int len;&n... 阅读全文
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
28 | 29 | 30 | 31 | 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
|
|