2013 通化邀请赛ABCDEGHIJ题解

A:

#include <cstdio>
#include <cstring>
int main() {
	int T;
	scanf("%d", &T);
	while(T --) {
		double x, ans = 0;
		for(int i = 0; i < 12;i ++) {
			scanf("%lf", &x);
			ans += x;
		}
		ans /= 12;
		char b[1000];
		sprintf(b,"%.2f", ans);
		int len = strlen(b);
		if(b[len-1] == '0' && b[len-2] == '0') b[len-3] = '\0';
		else if(b[len-1] == '0') b[len-1] = '\0';
		printf("$%s\n", b);
	}
	return 0;
}
B:

==明天再上代码,。
C:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define N 505
char mp[N][N];
int n,m;
int dp[N][N][4];
void work(){
	//**
	//*
	for(int i = n-1; i>= 1; i--)
		for(int j = m-1; j >= 1; j--)
		{
			int tmp = 1;
			for(int k = 1; i+k<=n && j+k<=m ; k++) {
				if(mp[i+k][j]==mp[i][j+k])
				tmp++;
				else break;
			}
			dp[i][j][3] = min(tmp, dp[i+1][j+1][3]+2);
		}
	//**
	// *
	for(int i = n-1; i >= 1; i--)
		for(int j = 2; j <= m; j++)
		{
			int tmp = 1;
			for(int k = 1; i+k<=n && j-k>0 ; k++) {
				if(mp[i+k][j]==mp[i][j-k])
				tmp++;
				else break;
			}
			dp[i][j][2] = min(tmp, dp[i+1][j-1][2]+2);
		}
	//*
	//**
	for(int i = 2; i <= n; i++)
		for(int j = m-1; j >= 1; j--)
		{
			int tmp = 1;
			for(int k = 1; i-k>0 && j+k<=m ; k++) {
				if(mp[i-k][j]==mp[i][j+k])
				tmp++;
				else break;
			}
			dp[i][j][1] = min(tmp, dp[i-1][j+1][1]+2);
		}

	// *
 	//**
	for(int i = 2; i <= n; i++)
		for(int j = 2; j <= m; j++)
		{
			int tmp = 1;
			for(int k = 1; i-k>0 && j-k>0 ; k++) {
				if(mp[i-k][j]==mp[i][j-k])
				tmp++;
				else break;
			}
			dp[i][j][0] = min(tmp, dp[i-1][j-1][0]+2);
		}
}
int main() {
	int i,j,k,T;scanf("%d",&T);
	while (T--) {
		scanf("%d%d",&n,&m);
		for(i = 1; i<= n; i++)	scanf("%s",mp[i]+1);
		memset(dp, 0, sizeof dp);
		work();
		for(i = 1; i <= n; i++)	for(j = 1; j <= m; j++)	for(k = 0; k < 4; k++)	dp[i][j][k] = max(dp[i][j][k], 1);
	
		int ans = 0;
		for(i = 1; i <= n; i++)
			for(j = 1; j <= m; j++)
				for(k = 0; k < 4; k++) {
					int len = dp[i][j][k];
					len = ((len+1)*len)/2;
					ans = max(ans, len);
				}
		cout<<ans<<endl;
	}
	return 0;
}
D:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef int ll;
#define N 100010
ll n, m;
ll f[N];
ll find(ll x){return x==f[x]?x:f[x]=find(f[x]);}
bool Union(ll x, ll y){
	ll fx = find(x), fy = find(y);
	if(fx==fy)return false;
	if(fx>fy)swap(fx,fy);
	f[fx] = fy;
	return true;
}
struct node{
	int from ,to;
}edge[100010];
vector<int>ans;
int main() {
	ll u,v,i,j;
	while(~scanf("%d %d",&n,&m)) {
		ans.clear();
		for(i = 0; i < n; i++)f[i] = i;
		for(i = 1; i <= m; i++) {
			scanf("%d %d",&edge[i].from, &edge[i].to);
		}
		int now = n;
		for(i = m; i >= 1; i--) {
			ans.push_back(now);
			u = edge[i].from, v = edge[i].to;
			if(Union(u,v))
			now--;
		}
		for(i = ans.size()-1; i>=0;i--)
		printf("%d\n",ans[i]);
	}
	return 0;
}
E:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
const int N = 100000;
std::vector<int> prime;
void prepare() {
	bool vis[N];
	for (int i = 2; i < N; ++i)
		if (!vis[i]) {
			prime.push_back(i);
			if ((ll)i * i >= N)
				continue;
			for (int j = i * i; j < N; j += i)
				vis[j] = true;
		}
}
int main() {
	prepare();
	int t, g, l, v, x;
	scanf("%d", &t);
	while (t -- > 0) {
		scanf("%d%d", &g, &l);
		if (g == 0 || l % g != 0 || g > l) {
			puts("0");
		} else {
			x = v = l / g;
			ll ans = 1;
			for (int i = 0; i < prime.size(); ++i) {
				if ((ll)prime[i] * prime[i] > x)
					break;
				if (v % prime[i] == 0) {
					int cnt = 0;
					while (v % prime[i] == 0) {
						v /= prime[i];
						++cnt;
					}
					ans = ans * 6 * cnt;
				}
			}
			if (v != 1) {
				ans *= 6;
			}
			printf("%I64d\n", ans);
		}
	}
	return 0;
}
G:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <iostream>
#include <algorithm>
const int N = 6;
int up[N][N], lef[N][N], vis[N][N];
int r, c, ans;

void dfs(int i, int j, int cnt) {
	if (i == r && j == c + 1) {
		if (cnt > ans)
			ans = cnt;
	} else if (j == c + 1)
		dfs(i + 1, 1, cnt);
	else {
		//not put
		if (!vis[i][j]) {
			lef[i][j] = lef[i][j - 1];
			up[i][j] = up[i - 1][j];
			dfs(i, j + 1, cnt);
		}
		//put
		
		if (vis[i][j]) {
			if (up[i - 1][j] == 1 || up[i - 1][j] == 3)
				up[i][j] = 2;
			else
				up[i][j] = 0;
			if (lef[i][j - 1] == 1 || lef[i][j - 1] == 3)
				lef[i][j] = 2;
			else
				lef[i][j] = 0;
			dfs(i, j + 1, cnt);
		} else {
			if (up[i - 1][j] == 2 || lef[i][j - 1] == 2 || up[i - 1][j] == 3 || lef[i][j - 1] == 3)
				return ;
			if (up[i - 1][j] == 1)
				up[i][j] = 3;
			else
				up[i][j] = 1;
			if (lef[i][j - 1] == 1)
				lef[i][j] = 3;
			else
				lef[i][j] = 1;
			dfs(i, j + 1, cnt + 1);
		}
	}
}

void work() {
	ans = 0;
	memset(lef, 0, sizeof lef);
	memset(up, 0, sizeof up);
	dfs(1, 1, 0);
	printf("%d\n", ans);
}

int main() {
	int m, x, y;
	while (~scanf("%d%d", &r, &c)) {
		memset(vis, 0, sizeof vis);
		
		scanf("%d", &m);
		while (m -- > 0) {
			scanf("%d%d", &x, &y);
			++ x;
			++ y;
			vis[x][y] = true;
		}
		
		work();
	}
	return 0;
}

H:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef int ll;
#define inf 100000000
#define N 40
ll n, m;
int a[N],b[N],sa[N],sb[N];
int x[N][N][N][N];
int dfs(int al, int ar, int bl, int br){ //先手面对这个局势时能获得的最大价值
	if(x[al][ar][bl][br]!=-1)
		return x[al][ar][bl][br];
	if(al>ar && bl>br)
		return 0;
	int c[4] = {0};
	int A, ans = 0, sum = sa[ar]-sa[al-1] + sb[br]-sb[bl-1];
	if(al<=ar) {
		c[0] = dfs(al+1, ar, bl, br);
		c[1] = dfs(al, ar-1, bl, br);
		A = sum - c[0];		ans = max(ans, A);
		A = sum - c[1];		ans = max(ans, A);
	}
	if(bl<=br) {
		c[2] = dfs(al, ar, bl+1, br);
		c[3] = dfs(al, ar, bl, br-1);
		A = sum - c[2];		ans = max(ans, A);
		A = sum - c[3];     ans = max(ans, A);
	}
	x[al][ar][bl][br] = ans;
 	return ans;
}

int main() {
	ll u,v,i,j,T;scanf("%d",&T);
	while(T--) {
		memset(x, -1, sizeof x);
		scanf("%d",&n);
		for(i = 1; i <= n; i++)scanf("%d",&a[i]);
		for(i = 1; i <= n; i++)scanf("%d",&b[i]);
		sa[0] = sb[0] = 0;
		for(i = 1; i <= n; i++) {
  			sa[i] = sa[i-1]+a[i];
			sb[i] = sb[i-1]+b[i];
		}
	//	for(i = 1; i <= n; i++)printf("%d ",sa[i]); puts("");
	//	for(i = 1; i <= n; i++)printf("%d ",sb[i]); puts("");

		printf("%d\n",dfs(1,n,1,n));
	}
	return 0;
}
I:

无码。。

J:

#include<cstdio>
const int mod = 2011;
const int e1 = 1944,e2 = 1609;//30,5的逆元
inline int qPow(int x,int p)
{
    int a=6,ans=1;
    while(x)
    {
        if(x&1) ans  = ans*a%p;
        a = a*a%p;
        x >>= 1;
    }
    return ans;
}
int main()
{
    int n,tmp,tmp1,tmp2,ans1,ans2;
    while(scanf("%d",&n),n)
    {
        tmp = qPow(n,mod);
        tmp1 = (tmp+24+mod)%mod;
        tmp2 = (tmp-1+mod)%mod;
        ans1 = tmp1*e1%mod;
        ans2 = tmp2*e2%mod;
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}



posted on 2017-08-04 08:31  ljbguanli  阅读(193)  评论(0编辑  收藏  举报