A
public class doorplate{
public static void main(String[] args){
int c=0;
for(int i=1;i<=2020;i++){
int a=i;
while(a>0){
if(a%10==2){
c++;
}
a/=10;
}
}
System.out.println(c);
}
}
B
public class fraction{
public static int o(int a,int b){//判断公约数
if(b==0){
return a;
}
return o(b,a%b);
}
public static void main(String[] args){
int c=0;
for(int i=1;i<=2020;i++){
for(int j=1;j<=2020;j++){
if(o(i,j)==1){
c++;
}
}
}
System.out.println(c);
}
}
C
public class snake{
public static void main(String[] args) {
int a=1;
for (int i = 1; i < 20; i++) {
a+=4*i;
}
System.out.println(a);
}
}
D
public class run{
public static void main(String[] args){
int[] a={0,31,28,31,30,31,30,31,31,30,31,30,31};
int y=2000,m=1,w=6,d=1,km=2;
while(y!=2020 || m!=10 || d!=1){
if((y%4==0 && y%100!=0) || y%400==0){
a[2]=29;
}else{
a[2]=28;
}
d++;
w=(w+1)%7;
if(d>a[m]){
m++;
d=1;
if(m>12){
y++;
m=1;
}
}
if(d==1 || w==1){
km++;
}
km++;
}
System.out.println(km);
}
}
E
public class SSC{
static int[] a={0,1,2,3,4,5,6};
//所有可能
private static int f(int ind,int n){
int c=0;
if(ind==n){
if(ch(n)){
c++;
}
}
for(int i=ind;i<7;i++){
{
int t=a[i];
a[i]=a[ind];
a[ind]=t;
}
c+=f(ind+1,n);
{
int t=a[i];
a[i]=a[ind];
a[ind]=t;
}
}
return c;
}
//连通
private static boolean ch(int n){
int c=0;
int[] ch=new int[7];
for(int j=0;j<n;j++){
ch[a[j]]=1;
}
for(int k=0;k<7;k++){
if(ch[k]==1){
g(ch,k);
c++;
}
}
return c==1;
}
private static void g(int[] ch,int ind){
ch[ind]=0;
if(ind==0){
if(ch[1]==1){
g(ch,1);
}
if(ch[5]==1){
g(ch,5);
}
if(ch[6]==1){
g(ch,6);
}
}
if(ind==1){
if(ch[0]==1){
g(ch,0);
}
if(ch[2]==1){
g(ch,2);
}
}
if(ind==2){
if(ch[1]==1){
g(ch,1);
}
if(ch[3]==1){
g(ch,3);
}
if(ch[6]==1){
g(ch,6);
}
}
if(ind==3){
if(ch[2]==1){
g(ch,2);
}
if(ch[4]==1){
g(ch,4);
}
if(ch[6]==1){
g(ch,6);
}
}
if(ind==4){
if(ch[3]==1){
g(ch,3);
}
if(ch[5]==1){
g(ch,5);
}
}
if(ind==5){
if(ch[0]==1){
g(ch,0);
}
if(ch[4]==1){
g(ch,4);
}
if(ch[6]==1){
g(ch,6);
}
}
if(ind==6){
if(ch[0]==1){
g(ch,0);
}
if(ch[2]==1){
g(ch,2);
}
if(ch[3]==1){
g(ch,3);
}
if(ch[5]==1){
g(ch,5);
}
}
}
public static void main(String[] args){
int an=7;
an+=f(0,2)/2;
an+=f(0,3)/6;
an+=f(0,4)/24;
an+=f(0,5)/120;
an+=7;
an+=1;
System.out.println(an);
}
}
F
import java.util.Scanner;
public class score{
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int sc;
int n1=0,n2=0;
int p1=0,p2=0;
for(int i=0;i<n;i++){
sc=scanner.nextInt();
if(sc>=60){
n1++;
}
if(sc>=85){
n2++;
}
}
p1=(int)((n1*1.0/n+0.005)*100);
p2=(int)((n2*1.0/n+0.005)*100);
System.out.println(p1+"%");
System.out.println(p2+"%");
}
}
G
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class date{
public static boolean t(String data){
String dt=data.substring(1,4)+"-"
+data.substring(4,6)+"-"+data.substring(6,8);
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
try {
simpleDateFormat.setLenient(false);
simpleDateFormat.parse(dt);
} catch (ParseException e){
return false;
}
return true;
}
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
long d=scanner.nextLong();
d++;
String[] Data = new String[1];
int ti=0;
while(true){
Data[0]=d+"";
if(Data[0].charAt(0)==Data[0].charAt(7) &&
Data[0].charAt(1)==Data[0].charAt(6) &&
Data[0].charAt(2)==Data[0].charAt(5) &&
Data[0].charAt(3)==Data[0].charAt(4) && t(Data[0]) && ti<1){
System.out.println(Data[0]);
ti++;
}
if(Data[0].charAt(0)==Data[0].charAt(2) &&
Data[0].charAt(2)==Data[0].charAt(5) &&
Data[0].charAt(5)==Data[0].charAt(7) &&
Data[0].charAt(1)==Data[0].charAt(3) &&
Data[0].charAt(3)==Data[0].charAt(4) &&
Data[0].charAt(4)==Data[0].charAt(6) &&
t(Data[0])){
System.out.println(Data[0]);
break;
}
d++;
}
}
}
H
import java.util.Arrays;
import java.util.Scanner;
public class Z{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] rv = sc.next().toCharArray();
int[][] dr = new int[26][2];
for (int i = 0; i < 26; ++i)
Arrays.fill(dr[i], -1);
int ans = 0, total = 0;
for (int i = 0; i < rv.length; ++i) {
int ind = rv[i] - 'a';
total += i - 2 * dr[ind][1] + dr[ind][0];
dr[ind][0] = dr[ind][1];
dr[ind][1] = i;
ans += total;
}
System.out.println(ans);
}
}
I
using System;
public class Class1
{
public Class1()
{
int N = 0;
int plans = 0;
cin >> N;
set<pair<double, double>> setab;
for (int a = 0; a < N; a++)
{
pair<double, double> temp;
cin >> temp.first >> temp.second;
setab.insert(temp);
}
set<pair<double, double>>::iterator i1 = setab.begin();
set<pair<double, double>> _setab;
for (; i1 != setab.end(); i1++)
{
pair<double, double> temp = *i1;
if (_setab.size() <= 0)
{
_setab.insert(temp);
plans = 2;
continue;
}
double AA = temp.first;
double BB = temp.second;
double x, y;
double A2, B2;
set<pair<double, double>> setcp;
set<pair<double, double>>::iterator i2 = _setab.begin();
for (; i2 != _setab.end(); iter2++)
{
A2 = i2->first; B2 = i2->second;
if (AA - A2 == 0)
{
_setab.insert(temp);
continue;
}
x = (B2 - BB) / (AA - A2); y = (AA * B2 - A2 * BB) / (AA - A2);
setcp.insert(pair<double, double>(x, y));
}
plans += (setcp.size() + 1);
_setab.insert(temp);
}
cout << plans << endl;
return 0;
}
}
J
|