希望决赛题目不搞我
先挂
#1 平方末尾
本题满分: 15分
问题描述
能够表示为某个整数的平方的数字称为“平方数”
比如,25,64
虽然无法立即说出某个数是平方数,但经常可以断定某个数不是平方数。
因为平方数的末位只可能是:[0, 1, 4, 5, 6, 9] 这6个数字中的某个。
所以,4325435332必然不是平方数。
如果给你一个2位或2位以上的数字,你能根据末位的两位来断定它不是平方数吗?
请计算一下,一个2位以上的平方数的最后两位有多少种可能性?
答案提交
注意:需要提交的是一个整数,表示2位以上的平方数最后两位的不同情况数。
不要填写任何多余内容(比如,说明解释文字等)
22
calcCode:
import java.util.*;
public class Test {
public static void main(String[] args) {
int HIGH = 100000000;
Set<Integer> set = new HashSet();
for (int i = 10; i <= HIGH; i++) {
int n = (int)Math.sqrt(i);
if (n * n == i) set.add(i % 100);
}
System.out.println(set.size());
}
}
送分题
#2 七星填数
本题满分: 29分
问题描述
如图所示。
在七角星的14个节点上填入1~14 的数字,不重复,不遗漏。
要求每条直线上的四个数字之和必须相等。
图中已经给出了3个数字。
请计算其它位置要填充的数字,答案唯一。
填好后,请提交绿色节点的4个数字(从左到右,用空格分开)
比如:12 5 4 8
当然,这不是正确的答案。
答案提交
注意:只提交4个用空格分开的数字,不要填写任何多余的内容。
10 3 9 8
先打个记号
calcCode:
import java.util.*;
public class Test {
static int clearLove[] = { 1, 2, 3, 4, 5, 7 ,8 ,9 ,10, 12, 13};
public static void main(String[] args) {
do if (beFine()) break;
while (next(clearLove));
for (int i = 0; i < 4; i++)
System.out.print(clearLove[i] + " ");
}
static boolean next(int[] a) {
int i = a.length - 2;
while (i >= 0 && a[i] > a[i + 1]) i--;
if (i < 0) return false;
int j = i + 1, t = a[i];
while (j < a.length && a[j] > t) j++;
a[i] = a[j - 1];
a[j - 1] = t;
Arrays.sort(a, i + 1, a.length);
return true;
}
static boolean beFine() {
int fine = clearLove[0] + clearLove[1] + clearLove[2] + clearLove[3];
if (clearLove[3] + clearLove[4] + clearLove[5] + clearLove[6] != fine) return false;
if (clearLove[6] + clearLove[7] + clearLove[8] + 14 != fine) return false;
if (14 + clearLove[9] + clearLove[1] + 6 != fine) return false;
if (6 + clearLove[2] + clearLove[4] + 11 != fine) return false;
if (11 + clearLove[5] + clearLove[7] + clearLove[10] != fine) return false;
if (clearLove[10] + clearLove[8] + clearLove[9] + clearLove[0] != fine) return false;
return true;
}
}
哪个小逼崽子又在暗示我
字典序枚举
再上个全排列
public class Test {
static int clearLove[] = { 1, 2, 3, 4, 5, 7 ,8 ,9 ,10, 12, 13};
public static void main(String[] args) { next(clearLove); }
static void next(int[] a) { next(a, 0, a.length); }
static void next(int[] a, int start, int end) {
if (start == end) {
if (beFine()) {
for (int i = 0; i < 4; i++)
System.out.print(a[i] + " ");
System.out.println();
}
} else {
for (int i = start; i < end; i++) {
swap(a, i, start);
next(a, start + 1, end);
swap(a, i, start);
}
}
}
static void swap(int[] a, int i1, int i2) {
int t = a[i1];
a[i1] = a[i2];
a[i2] = t;
}
static boolean beFine() { . . . }
}
#3 打印数字
本题满分: 23分
问题描述
小明写了一个有趣的程序,给定一串数字。
它可以输出这串数字拼出放大的自己的样子。
比如“2016”会输出为:
22222 00000 1 6666
2 2 0 0 1 1 6
2 0 0 1 666666
2 0 0 1 6 6
2 0 0 1 6 6
2 2 0 0 1 6 6
2222222 00000 1111 66666
请仔细分析代码,填写划线部分缺少的内容。
public class Main
{
static void f(int n)
{
String[][] di =
{{" 00000 ",
"0 0",
"0 0",
"0 0",
"0 0",
"0 0",
" 00000 "},
{" 1 ",
" 1 1 ",
" 1 ",
" 1 ",
" 1 ",
" 1 ",
" 1111"},
{" 22222 ",
"2 2",
" 2",
" 2 ",
" 2 ",
" 2 2",
"2222222"},
{" 33333 ",
"3 3",
" 3",
" 3333 ",
" 3",
"3 3",
" 33333 "},
{" 44 ",
" 4 4 ",
" 4 4 ",
"4 4 ",
"4 4 ",
"4444444",
" 4 "},
{" 55555 ",
" 5 ",
"555555 ",
" 5",
" 5",
"5 5",
" 55555 "},
{" 6666 ",
"6 ",
"666666 ",
"6 6",
"6 6",
"6 6",
" 66666 "},
{"7777777",
"7 7 ",
" 7 ",
" 7 ",
" 7 ",
" 7 ",
" 7 "},
{" 88888 ",
"8 8",
"8 8",
" 88888 ",
"8 8",
"8 8",
" 88888 "},
{" 99999 ",
"9 9",
"9 9",
" 999999",
" 9",
"9 9",
" 99999 "}};
char[] cc = (""+n).toCharArray();
for(int i=0; i<di[0].length; i++){
for(int j=0; j<cc.length; j++){
System.out.print( ____________________ + " "); //填空位置
}
System.out.println();
}
}
public static void main(String[] args)
{
f(2016);
}
}
答案提交
注意:只提交划线部分缺少的代码,不要添加任何题面已有代码或符号。
也不要提交任何说明解释文字等。
di[cc[j] - '0'][i]
快删掉快删掉,这代码属实够恶心的
#4 赢球票
时间限制: 1.0s 内存限制: 256.0MB 本题满分: 31 分
问题描述
某机构举办球票大奖赛。获奖选手有机会赢得若干张球票。
主持人拿出 N 张卡片(上面写着 1~N 的数字),打乱顺序,排成一个圆圈。
你可以从任意一张卡片开始顺时针数数: 1,2,3…
如果数到的数字刚好和卡片上的数字相同,则把该卡片收入囊中,从下一个卡片重新数数。
直到再无法收获任何卡片,游戏结束。囊中卡片数字的和就是赢得球票的张数。
比如:
卡片排列是:1 2 3
我们从1号卡开始数,就把1号卡拿走。再从2号卡开始,但数的数字无法与卡片对上,
很快数字越来越大,不可能再拿走卡片了。因此这次我们只赢得了1张球票。
还不算太坏!如果我们开始就傻傻地从2或3号卡片数起,那就一张卡片都拿不到了。
如果运气好,卡片排列是 2 1 3
那我们可以顺利拿到所有的卡片!
本题的目标就是:已知顺时针卡片序列。
随便你从哪里开始数,求最多能赢多少张球票(就是收入囊中的卡片数字之和)
输入格式
第一行一个整数N(N<100),表示卡片数目
第二行 N 个整数,表示顺时针排列的卡片
输出格式
一行,一个整数,表示最好情况下能赢得多少张球票
测试样例1
Input:
3
1 2 3
Output:
1
测试样例2
Input:
3
2 1 3
Output:
6
code:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt(), max = 0;
int tuple[] = new int[n + 1];
boolean[] marked = new boolean[n + 1];
int head = in.nextInt(), pre = head, now, cnt;
for (int i = 1; i < n; i++) {
now = in.nextInt();
tuple[pre] = pre = now;
}
tuple[pre] = head;
for (int i = 1; i <= n; i++) {
now = 1;
pre = i;
cnt = head = 0;
Arrays.fill(marked, false);
while (now <= n && head < n) {
if (!marked[pre]) {
if (now == pre) {
head++;
now = 1;
cnt += pre;
marked[pre] = true;
} else now++;
}
pre = tuple[pre];
}
if (cnt > max) max = cnt;
}
System.out.print(max);
}
static class InputReader {
private InputStream in;
private int next, len;
private byte[] buff;
InputReader(InputStream in) { this(in, 8192); }
InputReader(InputStream in, int buffSize) {
this.buff = new byte[buffSize];
this.next = this.len = 0;
this.in = in;
}
private int getByte() {
if (next >= len)
try {
next = 0;
len = in.read(buff);
if (len == -1) return -1;
} catch (IOException e) {
e.fillInStackTrace();
}
return buff[next++];
}
private int split() {
int c = getByte();
while (c <= 32 || c == 127) c = getByte();
return c;
}
public int nextInt() {
int n = 0, c = split();
boolean flag = true;
if (c == '-') {
c = getByte();
flag = false;
}
while (c >= '0'&& c <='9') {
n = n * 10 + (c & 0xf);
c = getByte();
}
return flag? n: -n;
}
}
}
数据规模很小,暴力就能过
#5 路径之谜
时间限制: 1.0s 内存限制: 256.0MB 本题满分: 87 分
问题描述
小明冒充X星球的骑士,进入了一个奇怪的城堡。
城堡里边什么都没有,只有方形石头铺成的地面。
假设城堡地面是 n x n 个方格。
如图所示
按习俗,骑士要从西北角走到东南角。
可以横向或纵向移动,但不能斜着走,也不能跳跃。
每走到一个新方格,就要向正北方和正西方各射一箭。
(城堡的西墙和北墙内各有 n 个靶子)
同一个方格只允许经过一次。但不必做完所有的方格。
如果只给出靶子上箭的数目,你能推断出骑士的行走路线吗?
有时是可以的,比如图1.png中的例子。
本题的要求就是已知箭靶数字,求骑士的行走路径(测试数据保证路径唯一)
输入格式
第一行一个整数N(0<N<20),表示地面有 N x N 个方格
第二行N个整数,空格分开,表示北边的箭靶上的数字(自西向东)
第三行N个整数,空格分开,表示西边的箭靶上的数字(自北向南)
输出格式
一行若干个整数,表示骑士路径。
为了方便表示,我们约定每个小格子用一个数字代表,从西北角开始编号: 0,1,2,3…
比如,图中的方块编号为:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
测试样例1
Input:
4
2 4 3 4
4 3 3 3
Output:
0 4 5 1 2 3 7 11 10 9 13 14 15
code:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
public class Main {
static boolean[][] visit;
static int LOWBIT = 0x0000FFFF;
static int n, fine, endX, endY, row[], col[];
public static void main(String[] args) {
InputReader in = new InputReader(System.in, 256);
PrintWriter out = new PrintWriter(System.out);
n = in.nextInt();
row = new int[n];
col = new int[n];
endX = endY = n - 1;
visit = new boolean[n][n];
for (int i = 0; i < n; i++)
fine += row[i] = in.nextInt();
for (int i = 0; i < n; i++)
fine += col[i] = in.nextInt();
fine = fine / 2 - 1;
Deque<Integer> deque = new ArrayDeque();
visit[0][0] = true;
deque.push(0);
dfs(0, 0, 0, deque);
while (!deque.isEmpty()) {
int now = deque.pollLast();
out.print((now >> 16) * n + (now & LOWBIT));
out.write(' ');
}
out.close();
}
static int[] offsetX = { -1, 0, 1, 0 };
static int[] offsetY = { 0, 1, 0, -1 };
static boolean dfs(int x, int y, int d, Deque<Integer> deque) {
if (x == endX && y == endY) return d == fine;
for (int k = 0, i, j; k < 4; k++) {
i = x + offsetX[k];
j = y + offsetY[k];
if (i < 0 || i >= n || j < 0 || j >= n || visit[i][j] || col[i] == 0 || row[j] == 0) continue;
col[i]--;
row[j]--;
visit[i][j] = true;
deque.push((i << 16) | j);
if (dfs(i, j, d + 1, deque)) return true;
visit[i][j] = false;
deque.pop();
col[i]++;
row[j]++;
}
return false;
}
static class InputReader {
InputStream in;
int next, len;
byte[] buff;
InputReader(InputStream in) { this(in, 8192); }
InputReader(InputStream in, int buffSize) {
this.buff = new byte[buffSize];
this.next = this.len = 0;
this.in = in;
}
int getByte() {
if (next >= len)
try {
next = 0;
len = in.read(buff);
if (len == -1) return -1;
} catch (IOException e) {
e.fillInStackTrace();
}
return buff[next++];
}
int split() {
int c = getByte();
while (c <= 32 || c == 127) c = getByte();
return c;
}
int nextInt() {
int n = 0, c = split();
boolean flag = true;
if (c == '-') {
flag = false;
c = getByte();
}
while (c >= '0' && c <= '9') {
n = n * 10 + (c & 0xf);
c = getByte();
}
return flag? n: -n;
}
}
}
写了个深搜,不知道会不会超时
#6 碱基
时间限制: 1.0s 内存限制: 256.0MB 本题满分: 115 分
问题描述
生物学家正在对n个物种进行研究。
其中第i个物种的DNA序列为s[i],其中的第j个碱基为s[i][j],碱基一定是A、T、G、C之一。
生物学家想找到这些生物中一部分生物的一些共性,他们现在关注那些至少在m个生物中出现的长度为k的连续碱基序列。准确的说,科学家关心的序列用2m元组(i1,p1,i2,p2…im,pm)表示,
满足:
1<=i1<i2<…<im<=n;
且对于所有q(0<=q<k), s[i1][p1+q]=s[i2][p2+q]=…=s[im][pm+q]。
现在给定所有生物的DNA序列,请告诉科学家有多少的2m元组是需要关注的。如果两个2m元组有任何一个位置不同,则认为是不同的元组。
输入格式
输入的第一行包含三个整数n、m、k,两个整数之间用一个空格分隔,意义如题目所述。
接下来n行,每行一个字符串表示一种生物的DNA序列。
DNA序列从1至n编号,每个序列中的碱基从1开始依次编号,不同的生物的DNA序列长度可能不同。
输出格式
输出一个整数,表示关注的元组个数。
答案可能很大,你需要输出答案除以1000000007的余数。
测试样例1
Input:
3 2 2
ATC
TCG
ACG
Output:
2
测试样例2
Input:
4 3 3
AAA
AAAA
AAA
AAA
Output:
7
评测用例规模与约定
对于20%的数据,k<=5,所有字符串总长L满足L <=100
对于30%的数据,L<=10000
对于60%的数据,L<=30000
对于100%的数据,n<=5,m<=5,1<=k<=L<=100000
保证所有DNA序列不为空且只会包含’A’ ’G’ ’C’ ’T’四种字母
code:
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
Map<String, int[]> map = new HashMap();
String now, key;
int[] val;
for (int i = 0; i < n; i++) {
now = in.readLine();
for (int j = 0, high = now.length() - k; j <= high; j++) {
key = now.substring(j, j + k);
val = map.get(key);
if (val == null)
map.put(key, val = new int[n]);
val[i]++;
}
}
Iterator<int[]> iterator = map.values().iterator();
int fow, tot, sum, cnt = 0;
while (iterator.hasNext()) {
val = iterator.next();
sum = tot = fow = 0;
for (int i = 0; i < n; i++) {
if (val[i] > 0) {
fow++;
if (fow >= m)
sum += val[i] * tot;
tot += val[i];
}
}
cnt = (cnt + sum) % MOD;
}
System.out.print(cnt);
}
static class InputReader {
InputStream in;
int next, len;
byte[] buff;
InputReader(InputStream in) { this(in, 8192); }
InputReader(InputStream in, int buffSize) {
this.buff = new byte[buffSize];
this.next = this.len = 0;
this.in = in;
}
int getByte() {
if (next >= len)
try {
next = 0;
len = in.read(buff);
if (len == -1) return -1;
} catch (IOException e) {
e.fillInStackTrace();
}
return buff[next++];
}
int split() {
int c = getByte();
while (c <= 32 || c == 127) c = getByte();
return c;
}
int nextInt() {
int n = 0, c = split();
boolean flag = true;
if (c == '-') {
c = getByte();
flag = false;
}
while (c >= '0' && c <= '9') {
n = n * 10 + (c & 0xf);
c = getByte();
}
return flag? n: -n;
}
String readLine() {
StringBuilder res = new StringBuilder();
int c = split();
while (c != '\n') {
res.appendCodePoint(c);
c = getByte();
}
return res.toString();
}
}
}
也算是道简单题吧