Time limit : 2sec / Memory limit : 1024MB
Score : 100 points
You are given four digits N1,N2,N3 and N4. Determine if these can be arranged into the sequence of digits "1974".
Input is given from Standard Input in the following format:
N1 N2 N3 N4
If N1,N2,N3 and N4 can be arranged into the sequence of digits "1974", print YES
; if they cannot, print NO
.
Copy
1 7 9 4
Copy
YES
We can get 1974 by swapping N2 and N3.
Copy
1 9 7 4
Copy
YES
We already have 1974 before doing anything.
Copy
1 2 9 1
Copy
NO
Copy
4 9 0 8
Copy
NO
水题
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String args[])throws IOException {
while(in.hasNext())
{
int []a=new int[4+1];
int []vis=new int[11];
for(int i=1;i<=4;i++)
{
a[i]=in.nextInt();
vis[a[i]]++;
}
if(vis[1]==1&&vis[7]==1&&vis[9]==1&&vis[4]==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
A string is called a KEYENCE string when it can be changed to keyence
by removing its contiguous substring (possibly empty) only once.
Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
Input is given from Standard Input in the following format:
S
If S is a KEYENCE string, print YES
; otherwise, print NO
.
Copy
keyofscience
Copy
YES
keyence
is an abbreviation of key of science
.
Copy
mpyszsbznf
Copy
NO
Copy
ashlfyha
Copy
NO
Copy
keyence
Copy
YES
Submit
这题其实也很水,但是我在一种方法上卡死了,到底不知道那种方法哪里错了,结果比完赛后,换了一种方法就过了,这题的关键就是肯定要删除连续的len-7个字符。暴力枚举即可
AC代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String args[])throws IOException {
String s=in.nextLine();
int len1=s.length();
String s1=s;
String str="keyence";
int len=str.length();
int pos=s.indexOf(str);
if(pos!=-1&&(pos==0||pos==len1-len))
{
System.out.println("YES");
return ;
}
int t=len1-len;
for(int i=1;i
不知道怎么错的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String args[])throws IOException {
while(in.hasNext())
{
String s=in.nextLine();
int len1=s.length();
String str="keyence";
int len=str.length();
int pos=s.indexOf(str);
int pos3=s.lastIndexOf(str);
if(pos==0||pos==len1-len)
{
System.out.println("YES");
return ;
}
for(int i=1;i
Time limit : 2sec / Memory limit : 1024MB
Score : 400 points
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is Ai, and according to his investigation, it is known that he needs readiness of at least Bi in order to pass the i-th examination.
Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness.
For Takahashi, find the minimum possible number of indices i such that Ai and Ci are different, for a sequence C1,C2,…,CN that satisfies the following conditions:
If such a sequence C1,C2,…,CN cannot be constructed, print −1.
Input is given from Standard Input in the following format:
N A1 A2 … AN B1 B2 … BN
Print the minimum possible number of indices i such that Ai and Ci are different, for a sequence C1,C2,…,CN that satisfies the conditions. If such a sequence C1,C2,…,CN cannot be constructed, print −1.
Copy
3 2 3 5 3 4 1
Copy
3
(A1,A2,A3)=(2,3,5) and (B1,B2,B3)=(3,4,1). If nothing is done, he cannot pass the first and second exams. The minimum possible number of indices i such that Ai and Ci are different, 3, is achieved when:
Copy
3 2 3 3 2 2 1
Copy
0
In this case, he has to do nothing in order to pass all the exams.
Copy
3 17 7 1 25 6 14
Copy
-1
In this case, no matter what is done, he cannot pass all the exams.
Copy
12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212
Copy
5
如果a[i]b[i]的位置来互换,但有时后可以互换三下来解决问题。
我们先设sum为当a[i]
当a[i]>b[i]时来消除,当然越大消除的sum越多,所以,排序一下,消除到sum为0.
答案ans:a[i]
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String args[])throws IOException {
int n=in.nextInt();
long[] a=new long[n+1];
long[] b=new long[n+1];
ArrayList