Number of briquettes
There is a heap of coal, which is made into a triangular pyramid. Specific:
1 on the first floor,
The second layer is 3 (arranged into triangles),
The third layer is 6 (arranged into triangles),
Fourth floor 10 (arranged into triangles),
....
If there is a total of 100 layers, how many coals are there?
Please fill in the number of the total number of coals.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.
171700
public class Main {public
static void Main (string[] args) {
int ans = 0;
for (int i = 1; I <= ++i)
ans + = (1+i) *i/2;
System.out.println (ANS);
}
Birthday Candles
A gentleman has held a birthday party every year since the beginning of a year, and has to blow out candles with the same number of ages.
Now, he blew out 236 candles altogether.
How old did he begin his birthday party, please?
Please fill in the age of his birthday party.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.
26
public class Main {public
static void Main (string[] args) {for
(int i = 1; I <= ++i) {
int sum = 0;
for (int j = i; J <=; ++j) {
sum = j;
if (sum = = 236)
System.out.println (i)
;
}
}}
arithmetic
B DEF
A +---+-------= 10
C GHI
In this formula, A~i represents the number of 1~9, and different letters represent different numbers. (The game is subject to change)
Like what:
6+8/3+952/714 is a solution,
5+3/1+972/486 is another solution.
How many solutions are there in this formula?
Note: You submit should be an integer, do not fill in any superfluous content or descriptive text.
29
public class main{static int count = 0;
static void Swap (char array[], int a, int b) {Char temp = array[a];
Array[a] = array[b];
ARRAY[B] = temp;
Static Boolean check (char[] str) {double[] num = new DOUBLE[10];
for (int i = 0; i < 9; ++i) num[i] = str[i]-' 0 ';
if (num[0]+num[1]*1.0/num[2]+ (num[3]*100+num[4]*10+num[5]) *1.0/(num[6]*100+num[7]*10+num[8) = =) return true;
return false;
static void permutation (char[] str, int a, int length) {if (a = = length) {if (check (str)) {
++count;
SYSTEM.OUT.PRINTLN (string.valueof (str));
}else{for (int i = A; I <= length; ++i) {swap (str, I, a);
Permutation (str, a + 1, length);
Swap (str, I, a); }} public static void Main (string[] args) {char[] str = "123456789". ToCharArray ();
Permutation (str, 0, 8);
System.out.println (count); }
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10];
void Print () {
for (int i = 0; i < 9; i++)
printf ("%d", A[i]);
printf ("\ n");
}
int main () {
int cnt = 0;
for (int i = 0; i < 9; ++i)
a[i] = i+1;
do{
if (a[0]+a[1]*1.0/a[2]+ (a[3]*100+a[4]*10+a[5)) *1.0/(a[6]*100+a[7]*10+a[8]) = = (++cnt)
;
Print ();
}
} while (Next_permutation (a,a+9));
printf ("%d\n", CNT);
return 0;
}
Sub -Group
9 Athletes in the competition, need to be divided into 3 groups for the preliminary.
What are the grouping schemes?
We mark the athletes as A,b,c,... I
The following program lists all the grouping methods.
The normal output of the program is:
ABC DEF GHI
ABC DEG FHI
ABC DEH FGI
ABC DEI FGH
ABC DFG EHI
ABC DFH EGi
ABC DFI Egh
ABC DGH EFI
ABC DGI EFH
ABC DHI EFG
ABC EFG DHI
ABC EFH DGI
ABC EFI DGH
ABC Egh DFI
ABC EGi DFH
ABC EHI DFG
ABC FGH DEI
ABC FGI DEH
ABC FHI DEG
ABC GHI DEF
ABD CEF GHI
ABD CEG FHI
ABD CEH FGI
ABD CEI FGH
ABD CFG EHI
ABD CFH EGi
ABD CFI Egh
ABD CGH EFI
ABD CGI EFH
ABD CHI EFG
ABD EFG CHI
..... (The following omitted, a total of 560 lines).
public class A
{public
static string remain (int[] a)
{
string s = "";
for (int i=0; i<a.length; i++) {
if (a[i] = = 0) s + = (char) (i+ ' a ');
}
return s;
}
public static void F (String s, int[] a)
{for
(int i=0; i<a.length; i++) {
if (a[i]==1) continue;
A[i] = 1;
for (int j=i+1; j<a.length; J + +) {
if (a[j]==1) continue;
A[j]=1;
for (int k=j+1; k<a.length; k++) {
if (a[k]==1) continue;
A[k]=1;
System.out.println (__________________________________); Fill in the blank position
a[k]=0;
}
a[j]=0;
}
A[i] = 0;
}}
public static void Main (string[] args)
{
int[] a = new int[9];
A[0] = 1;
for (int b=1; b<a.length; b++) {
a[b] = 1;
for (int c=b+1; c<a.length; C + +) {
a[c] = 1;
String s = "a" + (char) (b + ' a ') + (char) (c+ ' a ');
f (s,a);
A[c] = 0;
}
A[B] = 0;
}}}
Read the code carefully and fill in what is missing from the underlined part.
Note: Do not fill in any existing content or descriptive text.
System.out.println (s+ "" + (char) (' a ' +i) + (char) (' a ' +j) + (char) (' a ' +k) + "" +remain (a)); Fill in the blank position
Draw Lots Planet X is sending a 5-member observer mission to the W star.
which
A country can send up to 4 people.
Country B can send up to 2 people.
C Country can send up to 2 people.
....
So how many different combinations of country will there be in the final observer mission to W?
The following procedure solves the problem.
Array a[] is the largest number of places that each country can send.
Program execution results are:
Defff
Cefff
Cdfff
Cdeff
Ccfff
Cceff
Ccdff
Ccdef
Befff
Bdfff
Bdeff
Bcfff
Bceff
Bcdff
Bcdef
....
(The following omitted, a total of 101 lines)
public class A
{public
static void F (int[] A, int k, int n, String s)
{
if (k==a.length) {
if (n==0) Sys Tem.out.println (s);
return;
}
String s2 = s;
for (int i=0; i<=a[k]; i++) {
_____________________________; Fill in the position
s2 + = (char) (k + ' A ');
}
public static void Main (string[] args)
{
int[] a = {4,2,2,1,1,3};
F (a,0,5, "");
}
}
Read the code carefully and fill in what is missing from the underlined part.
Note: Do not fill in any existing content or descriptive text.
f (a,k+1,n-i,s2); Fill in the blank position
Square Fill Number
Like the next 10 squares
+--+--+--+
| | | |
+--+--+--+--+
| | | | |
+--+--+--+--+
| | | |
+--+--+--+
(If there is a problem, you can also see the following figure)
Fill in the 0~9 number. Requirement: Consecutive two digits cannot be contiguous.
(around, up and down, diagonal are counted adjacent)
A total number of possible filling schemes.
Please fill in an integer representing the number of scenarios.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.
1580
public class main{static int count = 0;
static void Swap (char array[], int a, int b) {Char temp = array[a];
Array[a] = array[b];
ARRAY[B] = temp; Static Boolean check (char [] str) {if (Check2 (str[0], str[1]) && Check2 (str[0], str[3]) &am p;& Check2 (str[0], str[4]) && Check2 (str[0], str[5]) && Check2 (str[1), str[2]) &am p;& Check2 (str[1], str[4]) && Check2 (str[1], str[5]) && Check2 (str[1), str[6]) ;& Check2 (str[2], str[5]) && Check2 (str[2], str[6]) && Check2 (str[3), Str[4]) & & Check2 (Str[3], str[7]) && Check2 (str[3], str[8]) && Check2 (str[4), str[5]) && Amp Check2 (Str[4], str[7]) && Check2 (Str[4], str[8]) && Check2 (str[4), str[9]) && C Heck2 (Str[5], str[6]) && Check2 (str[5), str[8]) && check2 (Str[5], str[9]) && Check2 (Str[6], str[9]) && Check2 (str[7), str[8]) && Check2
(Str[8], str[9])
return true;
return false; Static Boolean Check2 (char C, char D) {//TODO auto-generated method stub if (c = = (d+1) | |
c = = (D-1)) return false;
return true;
static void permutation (char[] str, int a, int length) {if (a = = length) {if (check (str)) {
count++;
SYSTEM.OUT.PRINTLN (string.valueof (str));
}else{for (int i = A; I <= length; ++i) {swap (str, I, a);
Permutation (str, a + 1, length);
Swap (str, I, a);
}} public static void Main (string[] args) {char[] str = "0123456789". ToCharArray ();
Permutation (str, 0, 9);
System.out.println (count); }
}
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
int a[10];
BOOL Check2 (int c,int d) {if (c = = D+1 | | c = = d-1) return false;
return true;
void Print () {for (int i = 0; i < i++) printf ("%d", a[i]);
printf ("\ n"); BOOL Check (int str[]) {if (Check2 (str[0), str[1]) && Check2 (str[0], str[3]) && Check2 (str[0), str[4] ) && Check2 (str[0], str[5]) && Check2 (str[1], str[2]) && Check2 (str[1), Str[4]) & amp;& Check2 (str[1], str[5]) && Check2 (str[1], str[6]) && Check2 (str[2), str[5]) ;& Check2 (str[2], str[6]) && Check2 (str[3], str[4]) && Check2 (str[3), str[7]) &&A mp Check2 (Str[3], str[8]) && Check2 (Str[4], str[5]) && Check2 (str[4), str[7]) && che Ck2 (Str[4], str[8]) && Check2 (Str[4], str[9]) &&Check2 (Str[5], str[6]) && Check2 (str[5], str[8]) && Check2 (str[5), str[9]) && che
Ck2 (Str[6], str[9]) && Check2 (Str[7], str[8]) && Check2 (str[8), str[9]) return true;
return false;
int main () {int cnt = 0;
for (int i = 0; i < ++i) a[i] = i;
do{if (check (a)) {++cnt;
Print ();
}}while (Next_permutation (a,a+10));
printf ("%d\n", CNT);
return 0;
}
Cut Stamps
As in "Figure 1", there are 12 pieces of the 12 zodiac stamps linked together.
Now you have to cut 5 from it, and the requirement must be attached.
(Connecting only one corner is not connected)
For example, "Figure 2", "Figure 3", the pink part is a qualifying cut.
Please calculate how many different cutting methods there are altogether.
Please fill in an integer representing the number of scenarios.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.
Import Java.util.HashSet;
public class main{public static int count = 0;
public static int [] A = new int[5];
public static hashset<string> HashSet = new hashset<string> ();
private static Boolean check () {//TODO auto-generated Method Stub boolean flag[] = new BOOLEAN[5];
DFS (flag,0);
Return flag[0]&&flag[1]&&flag[2]&&flag[3]&&flag[4]; } private static void Dfs (boolean[] flag,int N) {//TODO auto-generated method stub flag[n]
= true; for (int i = 0; i < 5; i++) {//plus one minus one to be in the same row, plus four minus four to be in the same column if (!flag[i] && (A[I]/4 = = A[N]/4)
&& (a[i] = = A[n]-1 | | a[i] = = A[n] + 1) {DFS (flag,i);
} if (!flag[i] && (a[i]%4 = = a[n]%4) && (a[i] = = A[n]-4 | | a[i] = = A[n] + 4)) {
DFS (flag,i);
}
}
} public static void Main (string[] args) {//TODO auto-generated a stub for (a[0) = 0; A[0] < 12;
++a[0]) {for (a[1] = a[0]+1 a[1] < ++a[1]) {for (a[2] = a[1]+1; a[2] <; ++a[2]) { for (a[3] = a[2]+1 A[3] < ++a[3]) {for (a[4] = a[3]+1; A[4] < 12; ++a[4]) {if (check ()) {Hashset.add ("" +a[0]+a[1]+a[2]+a[3]+a
[4]); {}}}}} System.out.println (has
Hset.size ()); }
}
Four squared and
The four square sum theorem, also known as Lagrange's theorem:
Each positive integer can be expressed as the sum of squares of up to 4 positive integers.
If you include 0, you can just say the sum of squares of 4 numbers.
Like what:
5 = 0^2 + 0^2 + 1^2 + 2^2
7 = 1^2 + 1^2 + 1^2 + 2^2
(^ symbol denotes the meaning of the exponentiation)
For a given positive integer, there may be many representations of the sum of squares.
Ask you to sort 4 numbers:
0 <= a <= b <= c <= D
And all possible representations are pressed a,b,c,d for the Union primary key in ascending order, and the first representation is finally exported
Program input as a positive integer N (n<5000000)
Requires output of 4 non-negative integers, sorted from small to large, separated by spaces in the middle
For example, enter:
5
The program should output:
0 0 1 2
Again, for example, enter:
12
The program should output:
0 2 2 2
Again, for example, enter:
773535
The program should output:
1 1 267 838
Resource conventions:
Peak memory consumption (including virtual machines) < 256M
CPU Consumption < 3000ms
Please output strictly according to the requirements, do not superfluous print similar: "Please enter ..." Superfluous content.
All the code is placed in the same source file, after debugging, the copy is submitted to the source.
Note: Do not use package statements. Do not use jdk1.7 and the above version of the features.
Note: The name of the main class must be: main, otherwise it will be handled in an invalid code.
Import Java.util.Scanner;
public class Main {public
static void Main (String [] args) {
Scanner SCA = new Scanner (system.in);
int n = sca.nextint ();
int MAXN = (int) math.sqrt (n);
Boolean flag = true;
for (int a = 0; a <= maxn && flag, ++a) {for
(int b = A; b <= maxn && flag; ++b) {for
(int c = b C <= MAXN && flag; ++C) {
int d = (int) math.sqrt (n-a*a-b*b-c*c);
if (n = = a*a+b*b+c*c+d*d) {
System.out.println (+ "" +b+ "" +c+ "" +d);
Flag = FALSE;}}}
game of taking the ball
Two people play the game of taking the ball.
A total of n balls, each rotation takes the ball, each of the collection {N1,N2,N3} should be any number.
If you cannot continue to fetch the ball, the game is over.
At this point, the party holding the odd number of balls wins.
If both are odd, it is a draw.
Assuming that both sides adopt the smartest method,
The first one who takes the ball is sure to win it.
Try programming to solve this problem.
Input format:
The first line of 3 positive integers N1 n2 N3, separated by spaces, indicating the number of desirable each time (0<n1,n2,n3<100)
The second line is 5 positive integers x1 x2 ... x5, spaces separate, representing the initial number of balls for 5 innings (0<xi<1000)
Output format:
A line of 5 characters, separated by a space. respectively, whether the first person to take the ball to win the game.
If you can win, you output +,
Secondly, if there is a way to force the opponent, output 0,
In any case will lose, then output-
For example, enter:
1 2 3
1 2 3 4 5
The program should output:
+ 0 + 0-
Again, for example, enter:
1 4 5
10 11 12 13 15
The program should output:
0-0 + +
Again, for example, enter:
2 3 5
7 8 9 10 11
The program should output:
+ 0 0 0 0
Resource conventions:
Peak memory consumption (including virtual machines) < 256M
CPU Consumption < 3000ms
Please output strictly according to the requirements, do not superfluous print similar: "Please enter ..." Superfluous content.
All the code is placed in the same source file, after debugging, the copy is submitted to the source.
Note: Do not use package statements. Do not use jdk1.7 and the above version of the features.
Note: The name of the main class must be: main, otherwise it will be handled in an invalid code.
Code (incorrect):
Import Java.util.Scanner;
public class Main {public static int [] num = new INT[3];
public static int [] init = new INT[5];
public static int [] end = new int[1000];
public static char [] sign = {'-', ' 0 ', ' 0 ', ' + '};
public static void Main (String [] args) {Scanner SCA = new Scanner (system.in);
for (int i = 0; i < 3; i++) num[i] = Sca.nextint ();
int minn = Math.min (Num[0], math.min (num[1), num[2]);
for (int i = 0; i < 5; i++) Init[i] = Sca.nextint ();
for (int i = 0; i < minn i++) end[i] = 2;
for (int i = Minn I < end.length; i++) {int temp = 0;
for (Int J =0 J < 3; J + +) {if (I-num[j] < 0) continue;
else if (end[i-num[j]] = = 3) {if (num[j]%2!= 0) temp = 1 > Temp 1:temp;
else if (end[i-num[j]] = = 0) {if (num[j]%2 = = 0) temp = 3; else temp = 2 > Temp?
2:temp;
else if (end[i-num[j]] = = 2) {if (num[j]%2==0) temp = 2 > Temp 2:temp; else Temp= 3;
else if (end[i-num[j]] = = 1) {if (num[j]%2==0) temp = 1 > Temp 1:temp;
} End[i] = temp;
for (int i = 0; i < 5; i++) {System.out.print (sign[end[init[i]]]+ ""); }
}
}
Compression Transformation
Xiaoming is studying the compression algorithm recently.
He knew that when compressed, if the number can be very small, can be encoded by the entropy to obtain a higher compression ratio.
However, it is a challenge to make the numbers small.
Recently, Xiaoming needs to compress a sequence of positive integers, which are characterized by the likelihood that the numbers that appear later are likely to be the numbers that have just recently appeared. For this particular sequence, xiaoming prepares a transform of the sequence to reduce the value of the number.
The process of transformation is as follows:
Enumeration sequence from left to right, each enumeration to a number, if the number does not appear, just convert the number to its opposite number, and if the number appears, see that it appears after the last occurrence in the original sequence (and before the current number), replacing the original number with the number of this category.
For example, sequences (A1, A2, A3, A4, A5) = (1, 2, 2, 1, 2) in the transformation process are:
A1:1 did not appear, so A1 into 1;
A2:2 did not appear, so A2 into 2;
A3:2 appeared, the last time for the original sequence of A2, after A2, A3 before there are 0 kinds of numbers, so A3 into 0;
A4:1 appeared, the last time for the original sequence of A1, after A1, A4 before there are 1 kinds of numbers, so A4 into 1;
A5:2 appeared, the last time for the original sequence of A3, after A3, A5 before there are 1 kinds of numbers, so A5 into 1.
Now, given the original sequence, what is the sequence of transformations according to this transformation rule.
Input format:
Enter the first row contains an integer n that represents the length of the sequence.
The second row contains n positive integers that represent the input sequence.
Output format:
The output line, containing the number of N, represents the transformed sequence.
For example, enter:
5
1 2 2 1 2
The program should output:
-1-2 0 1 1
Again, for example, enter:
12
1 1 2 3 2 3 1 2 2 2 3-1
The program should output:
-1 0-2-3 1 1 2 2 0 0 2 2
Data size and convention
For 30% of the data,n<=1000;
For 50% of the data,n<=30000;
For 100% of the data, 1 <=n<=100000,1<=ai<=10^9
Resource conventions:
Peak memory consumption (including virtual machines) < 256M
CPU Consumption < 3000ms
Please output strictly according to the requirements, do not superfluous print similar: "Please enter ..." Superfluous content.
All the code is placed in the same source file, after debugging, the copy is submitted to the source.
Note: Do not use package statements. Do not use jdk1.7 and the above version of the features.
Note: The name of the main class must be: main, otherwise it will be handled in an invalid code.
Import Java.util.HashSet;
Import Java.util.Scanner;
public class main{
static int cnt =-1;
Static int[] A,b;
public static void Main (String [] args) {
Scanner SCA = new Scanner (system.in);
while (Sca.hasnext ()) {
int n = sca.nextint ();
A = new int[n+5];
b = new Int[n+5];
for (int i = 0; i < n; ++i) {
A[i] = Sca.nextint ();
B[i] = A[i];
}
int cnt =-1;
for (int i = 0; i < n; ++i)
b[i] = solve (i);
for (int i = 0; i < n-1 ++i)
System.out.print (b[i]+ "");
System.out.println (b[n-1]);
}
static int solve (int n) {
int tmp = a[n];
hashset<integer> hashset = new hashset<integer> ();
for (int i = n-1 i >= 0;-i) {
if (a[i] = = tmp) {return
hashset.size ();
}
Hashset.add (A[i]);
Return cnt--
}
}