BigNum a, b, c, d;

char out[60005];

int main ()
  {
char in[50];
int flag;
int n;
int i, j;

while ( scanf ( "%s%d", &in, &n ) != EOF )
 {
int len = strlen ( in );
flag = 0;
for ( i=0; i<len; i++ )
 {
if ( in[i] == '.' )
 {
flag = ( len - i - 1 ) * n;
for ( j=i+1; j<len; j++ )
 {
in[j-1] = in[j];
}
in[j] = in[j+1];
len --;
break;
}
}

a.set ( "1", 1 );
b.set ( in, len );
c.set ( "0", 1 );

if ( ! Cmp ( b, c ) )
 {
printf ( "0\n" );
continue;
}

while ( n != 0 )
 {
if ( n & 1 )
 {
Mul ( a, b, c );
Cpy (a, c);
}
Cpy ( d, b );
Mul ( b, d, c );
Cpy ( b, c );
n >>= 1;

}

int l;
int count = 0;
int p = 0;
b.set ( "0", 1 );
while ( Cmp ( a, b ) || count <= flag )
 {
Div ( a, 10, l );
if ( count == flag && flag )
 {
out[p++] = '.';
}
out[p++] = (char)(l + '0');
count ++;
}

out[p] = '\0';
for ( i=0; i<p-1; i++ )
 {
if ( out[i] == '0' )
 {
out[i] = 0;
}
else
 {
if ( out[i] == '.' )
 {
out[i] = 0;
}
break;
}
}

if ( p>1 && out[p-1] == '0' )
 {
p --;
}
for ( i=p-1; out[i]!=0; i-- )
 {
printf ( "%c", out[i] );
}
printf ( "\n" );

}
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 >

 int ans[14] = { 2, 7, 5, 30, 169, 441, 1872, 7632, 1740, 93313, 459901, 1358657, 2504881, 13482720 };

int main()
  {

int k;

while ( scanf ( "%d", &k ) != EOF && k )
 {
printf( "%d\n", ans[k-1] );
}
return 0;
}


一个NOI题目,求的是一个二元一次不定方程组的整数解,使用扩展欧几里德算法及整数解公式。地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1061
#include <stdio.h>
__int64 x,y;
 __int64 extended_gcd(__int64 a,__int64 b) {
__int64 d,t;
 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;
}
 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
 {
if(m>n)
 {
d=extended_gcd((m-n),l);
b=y1-x1;
}
else
 {
d=extended_gcd((n-m),l);
b=x1-y1;
}
if(b%d!=0)printf("Impossible\n");
else
 {
s=x*(b/d)%l;
while(s<0)
s+=(l/d);
printf("%I64d\n",s);
}
}
return 0;
}

动态规划(DP),地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1080
#include <stdio.h>

 char tab[5] = {'A', 'C', 'G', 'T', '-'};

 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,
};

int str1[105];
int str2[105];

int dp[105][105];

int find(char ch)
  {
int i;
for (i=0; i<5; i++)
 {
if (tab[i]==ch)
 {
break;
}
}
return i;
}

int max(int a, int b, int c)
  {

int m = a;
if (b>m)
 {
m = b;
}
if (c>m)
 {
m = c;
}
return m;
}

int lcs(int s1[], int len1, int s2[], int len2)
  {

int i, j;
for (i=0; i<=len1; i++)
 {
for (j=0; j<=len2; j++)
 {
if (i==0 && j==0)
 {
dp[i][j] = 0;
}
else if (i==0 && j!=0)
 {
dp[i][j] = dp[i][j-1] + list[4][s2[j-1]];
}
else if (i!=0 && j==0)
 {
dp[i][j] = dp[i-1][j] + list[s1[i-1]][4];
}
else
 {
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];
}

int main()
  {

int t, n1, n2;
int i;
char temp[105];
while (scanf("%d", &t) != EOF)
 {
while (t--)
 {
scanf("%d%s", &n1, &temp);
for (i=0; i<n1; i++)
 {
str1[i] = find(temp[i]);
}
scanf("%d%s", &n2, &temp);
for (i=0; i<n2; i++)
 {
str2[i] = find(temp[i]);
}
printf("%d\n", lcs(str1, n1, str2, n2));
}
}
return 0;
}

摘要: 动态规划(DP),排序的时候使用的还是我自己写的快速排序,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1088
#include "stdio.h"typedef struct{ int h; int len;&n... 阅读全文
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论

阅读排行榜
评论排行榜
|
|