2016年东莞市信息特长生考试

15 篇文章 1 订阅
3 篇文章 0 订阅

2016年东莞市信息特长生考试

T1·字数整数

Description

Input

Output

Sample Input
15
Sample Output
22555
25555
28555
30000

Hint

Train of Thought

模拟

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int n, f;

int main()
{
	scanf("%d", &n);
	f = 1;
	for(int i = 10000; i <= 30000; i++)
	{
		int a = i % 1000;
		int b = (i % 10000) / 10;
		int c = i / 100;
		if(!(a % n) && !(b % n) && !(c % n))
		{
			printf("%d\n", i);
			f = 0;
		}
	}
	if(f)printf("No");
	return 0;
}

T2·游戏问题

Description

Input

Output

Sample Input
10 3 4 5
Sample Output
5

Hint

Train of Thought

就快速幂一下然后模n

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;

ll n, m, k, x;

#define ll long long
ll power(ll a, ll b)
{
	ll Ans = 1;
	a %= n;
	while(b)
	{
		if(b & 1)Ans = Ans * a % n; 
		a = a * a % n;
		b >>= 1;
	}
	return Ans;
}

int main()
{
	scanf("%lld%lld%lld%lld", &n, &m, &k, &x);
	printf("%lld", (power(10, k) * m + x) % n);
	return 0;
}

T3·字串距离

Description

Input

Output

Sample Input
cmc
snmn
2
Sample Output
10

Train of Thought

DP
F [ i ] [ j ] F[i][j] F[i][j]表示第一个字符串配对到第i位,第二个字符串配对到第j位的距离
F [ i ] [ j ] = m i n (   F [ i − 1 ] [ j ] + k ,    F [ i ] [ j − 1 ] + k ,    F [ i − 1 ] [ j − 1 ] + a b s ( s 1 [ i ] − s 2 [ j ] ) ) F[i][j] = min(\ F[i - 1][j] + k,\ \ F[i][j-1]+k,\ \ F[i-1][j-1] +abs(s1[i] - s2[j])) F[i][j]=min( F[i1][j]+k,  F[i][j1]+k,  F[i1][j1]+abs(s1[i]s2[j]))

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

int F[2005][2005]; 
int len1, len2, m, Ans;
string s1, s2;


int main()
{
	getline(cin, s1);
	len1 = s1.length(), s1 = ' ' + s1;
	getline(cin, s2);
	len2 = s2.length(), s2 = ' ' + s2;
	scanf("%d", &m);
	memset(F, 0x7f, sizeof(F));
	for(int i = 1; i <= len1; ++i)
		F[i][0] = m * i;
	for(int i = 1; i <= len2; ++i)
		F[0][i] = m * i;
	F[0][0] = 0;
	for(int i = 1; i <= len1; ++i)
		for(int j = 1; j <= len2; ++j)
		{
			F[i][j] = min(F[i - 1][j] + m, F[i][ j - 1] + m);
			F[i][j] = min(F[i][j], F[i - 1][j - 1] + abs(s1[i] - s2[j]));
		}
	printf("%d", F[len1][len2]);
}

T4·灾后重建

background

Description

在这里插入图片描述

Input

Output

Sample Input
4 5
1 2 3 4
0 2 1
2 3 1
3 1 2
2 1 4
0 3 5
4
2 0 2
0 1 2
0 1 3
0 1 4
Sample Output
-1
-1
5
4 	

Hint

Train of Thought

一开始看题,觉得数据不是很大
就直接暴力SPFA,结果只有20分[阿巴阿巴阿巴]
正解就Floyed
因为输入时间都是升序输入的
所以直接稍微处理一下就ok了

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;

ll h[100250], Time[100250], F[550][550];
ll INF, n, m, x, y, z, ques, k;

ll read()
{
	ll l = 0, r = 1;char c = getchar();
	while((c < '0' || c > '9') && c != '-')c = getchar();
	if(c == '-')r = -1, c = getchar();
	while((c >= '0' && c <= '9'))l = l * 10 + c - '0', c = getchar();
	return l * r;
}

int main()
{
	memset(F, 0x3f, sizeof(F));
	n = read(); m = read(); INF = F[0][0];
	for(ll i = 0; i < n; ++i)
		Time[i] = read(), F[i][i] = 0;
	for(ll i = 1; i <= m; ++i)
	{
		x = read(); y = read(); z = read();
		F[x][y] = F[y][x] = z;
	}
	ques = read(), k = 0;
	while(ques--)
	{
		x = read(); y = read(); z = read();
		while(Time[k] <= z && k <= n)//保证中间点的时间比z小
		{
			for(ll i = 0; i < n; ++i)
				for(ll j = 0; j < n; ++j)
					F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
			k++;
		}
		if(F[x][y] == INF || Time[x] > z || Time[y] > z)printf("-1\n");//保证起点、终点、中间点都小于z
		else printf("%d\n", F[x][y]);
	}
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值