现在的位置: 首页 > 综合 > 正文

21th Training

2013年10月03日 ⁄ 综合 ⁄ 共 1483字 ⁄ 字号 评论关闭

HNAU 21th Training Problem

第 21次训练                                           2013
/09 /30 AM

A.模拟     poj 2083
B.dp       poj 2411(经典dp)
C.数学     poj 2015(解密码)
D.搜索     poj 1659
E.贪心     poj 1755(或用单纯形方法)
F.图论     poj 1274 the perfect stall       最大流
G.高精度   poj 1405
H.动态规划 poj 2378

C.数学+模拟

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int i,j,k,n,d,x,l,a;
	char s[35],p[35],m[65],c[65];
	while(scanf("%d",&x)!=EOF && x)
	{
		getchar();
		gets(s);
		gets(p);
		gets(c);
		l=strlen(s);
		n=strlen(c);
		d = (int)(pow(1.0*n,1.5) + x) % n;
		memset(m,0,sizeof(m));
		for(i=0;i<l;i++) if(c[d]==s[i]) break;
		m[d]=p[i];
		for(i=d-1;(i+n)%n!=d;i--)
		{
			if(i<0) i=(i+n)%n;
			for(j=0;j<l;j++) if(c[i]==s[j]) break;
			for(k=0;k<l;k++) if(m[(i+1)%n]==s[k]) break;
			a=j^k;
			m[i]=p[a];
		}
		printf("%s\n",m);
	}
	return 0;
}


E. POJ   1659 Frogs' Neighborhood

给出无向图每个点的度数,问能否构造出一张完整的图满足度数的条件

G.高精度   poj 1405

题意:有n个人分遗产,每个人拿该遗产的1 / X (X为整数),后面的人拿的遗产不能大于前一个人的,但不能将遗产全部拿完,并且使剩下的遗产最少。

可以得出第一个人拿1/2, 第二个人不能1/2,可以拿1/3,以此类推,根据 每次剩下的遗产找规律;

第一次剩下:1/2    那么最多可以拿 1/3;
共拿走了(2+3)/(2*3);
第一次剩下:1/6    那么最多可以拿 1/7;
...
那么规律就出来了

f[a]=f[a-1]*(f[a-1]-1)+1

//package com;

import java.math.*;
import java.util.*;

public class Main{
	  
	public static void main(String args[])
	{
		BigInteger pre,now;
		BigInteger [] a=new BigInteger [20];
		a[1]=BigInteger.valueOf(2L);
		a[2]=BigInteger.valueOf(3L);
		
		pre=BigInteger.valueOf(6L);;//6 上次剩余的遗产量1/6
		int cnt=2;
		while(true)
	    {
	        now=pre.add(BigInteger.valueOf(1L));
	        a[++cnt]=now;
	        if(cnt>=18)break;
	        pre=pre.multiply(now);//下一个剩余的遗产量
	    }
		int n;
		Scanner in= new Scanner(System.in);
		while(in.hasNext())
		{
			n=in.nextInt();
			for(int i=1;i<=n;i++)
			System.out.println(a[i]);
		}
	}

}

抱歉!评论已关闭.