A.組原成績
花栗鼠科技大學(Hualishu University of Science and Technology, HUST)的計算機組成原理快要出分了,你現在需要計算你的組原成績如何構成,
具體來說,組原成績分為三部分,分別是平時出勤 ,作業 和考試 ,總成績 由如下公式計算:
其中我們保證
現在你知道了你的組原考試的 ,你希望計算你的總成績,
由于教務系統的特殊性,最終成績只能是整數,采取直接去掉小數部分的辦法,
輸入格式
一行三個整數,表示
輸出格式
一行一個整數,為
輸入樣例
50 100 100
輸出樣例
90
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String nextLine = sc.nextLine();
String[] split = nextLine.split(" ");
double t = Double.parseDouble(split[0]);
double h = Double.parseDouble(split[1]);
double e = Double.parseDouble(split[2]);
double cj=t*0.2+h*0.3+e*0.5;
System.out.println((int)cj);
}
}
B.報告賦分
花栗鼠科技大學的計算機組成原理實驗最終的結課考核方式是提交一份報告,
然而作為任課老師,蘿老師不希望大家過于內卷,所以指定了如下規定:
每份報告有一個卷面基礎分
在此基礎上:
若是報告字數低于 頁,則扣 分,如果分數低于 分了,則記作 分,
若是報告字數超過 頁,每超過 頁扣 分 ,直到分數扣到 分為止,
現在你知道了一份報告的卷面基礎分 和它的頁數 ,請你計算這份報告的最終得分,我們保證 .
輸入格式
本題有多組資料,
第一行一個整數 ,表示資料組數,
接下來 行,每行兩個整數 ,意義如題所示,
輸出格式
共 行,每行一個整數,表示該次詢問的資料最終的得分,
輸入樣例
2
70 17
80 10
輸出樣例
70
70
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String tS = sc.nextLine();
int t = Integer.parseInt(tS);
int[] arr = new int[t];
for(int i=0;i<t;i++) {
String nums = sc.nextLine();
String[] split = nums.split(" ");
int a=Integer.parseInt(split[0]);
int p=Integer.parseInt(split[1]);
if(p<16) {
if(a-10<0) {
a=0;
}else {
a-=10;
}
}else if(p>20){
int chao=p-20;
a-=chao;
if(a<0)a=0;
}
arr[i]=a;
}
for(int a:arr)System.out.println(a);
}
}
C.競爭得分
為了鼓勵大家寫出更好的作業,花栗鼠科技大學(Hualishu University of Science and Technology, HUST)的組原實驗采用了競爭得分的方式,
具體來說,假設有 個人提交了作業,并且其中原始得分最低的人記作 ,原始得分最高的人記作 ,第 個人的原始得分為 ,那么第 個人的得分就是:
由于成績系統的問題,最終錄入的成績只能是整數,采用直接去掉小數部分的方法,
輸入格式
第一行一個整數 表示人數,()
第二行共 個整數,為序列 ,其中 表示第 個人的原始作業得分,()
輸出格式
一行,共 個整數,表示經過更新后每個人的得分,
輸入樣例
3
1 2 3
輸出樣例
0 50 100
import java.util.Arrays;
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String nStr = sc.nextLine();
int n = Integer.parseInt(nStr);
int[] arr = new int[n];
String nextLine = sc.nextLine();
String[] split = nextLine.split(" ");
for(int i=0;i<split.length;i++) {
arr[i]=Integer.parseInt(split[i]);
}
int aMin=1001;
int aMax=0;
for(int a:arr) {
if(aMin>a)aMin=a;
if(aMax<a)aMax=a;
}
double fm=aMax-aMin;
for(int i=0;i<arr.length;i++) {
double fz=arr[i]-aMin;
int f=(int)(100*(fz/fm));
System.out.print(f+" ");
}
}
}
D.小卡與質數2
小卡最近迷上了質數,所以他想把任何一個數都轉化為質數!
小卡有次詢問,每次給你一個數字,問有多少個比小的非負整數,使得是質數,其中表示按位異或,
輸入格式
第一行一個正整數,表示有組詢問,
接下來行,每行一個正整數,
輸出格式
對于每組詢問,輸出一行一個整數,表示答案,
輸入樣例
9
5
6
7
8
9
10
100
1000
10000
輸出樣例
2
4
4
2
2
4
22
163
1132
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
public class Main4 {
public static int check(int number) {
int count=0;
for(int i=0;i<number;i++) {
int che = i^number;
if(checkZs(che)) {
count++;
}
}
return count;
}
public static boolean checkZs(int number) {
if(number==1)return false;
for(int i=2;i<=Math.sqrt(number);i++) {
if(number%i==0)return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String tStr = sc.nextLine();
int t = Integer.parseInt(tStr);
int[] arr = new int[t];
for(int i=0;i<t;i++) {
int nextInt = sc.nextInt();
arr[i]=check(nextInt);
}
//超時了
for(int a:arr)System.out.println(a);
}
}
E.蘿卜資料庫
花栗鼠很喜歡偷吃生產隊的大蘿卜,因此花栗鼠科技大學正在研究一種新型的資料庫,叫做蘿卜資料庫,
具體來說,它支持 個欄位,每個欄位名都是整數,里面存盤的數值也都是整數,
現在你支持如下操作:
向資料庫中插入一個記錄,它可能只會包含 個欄位的某一部分,具體的操作格式詳見“輸入格式”,
在資料庫中查詢有多少條符合條件的記錄,
現在你總共有 次操作(),請你對每個回答操作,輸出結果,
輸入格式
第一行兩個整數 ,意義如題所述,
接下來的若干行,每行代表一次操作,具體如下:
:表示一個插入操作,其中共有 個欄位,第 欄位的名字是 ,值為 .此處我們保證 ,并且 均為整數,
:表示一次查詢操作,表示查詢所有滿足 欄位 的值在 之間的記錄有多少個,
輸出格式
對于每個查詢操作,輸出一行一個整數,表示符合條件的記錄個數,
輸入樣例
4 5
1 2 1 2 2 4
2 2 1 5
1 2 3 5 4 6
2 4 7 8
輸出樣例
1
0
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String tStr = sc.nextLine();
String[] split = tStr.split(" ");
int n=Integer.parseInt(split[0]);
int k=Integer.parseInt(split[1]);
ArrayList<Integer> savaK = new ArrayList();
ArrayList<Integer> savaV = new ArrayList();
ArrayList<Integer> countList = new ArrayList();
for(int i=0;i<n;i++) {
String nextLine = sc.nextLine();
String[] split2 = nextLine.split(" ");
if(split2[0].equals("1")) {
for(int j=2;j<split2.length;j+=2) {
savaK.add(Integer.parseInt(split2[j]));
savaV.add(Integer.parseInt(split2[j+1]));
}
}else {
int x=Integer.parseInt(split2[1]);
int min=Integer.parseInt(split2[2]);
int max=Integer.parseInt(split2[3]);
int count=0;
for(int kIndex=0;kIndex<savaK.size();kIndex++) {
if(savaK.get(kIndex)==x) {
Integer integer = savaV.get(kIndex);
if(integer>=min&&integer<=max)count++;
}
}
countList.add(count);
}
}
for(Integer a:countList)System.out.println(a);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/386694.html
標籤:其他
