前言:就剩一场了
啊,今天下午这场,2点半才睡醒,爬起来开始写题。然后经历了最舒服的前1个小时和最自闭的后2个半小时。
A、模板
这个题不难,可以定义在签到题的位置上。但是!我一上场,一看题干,就和我之前做过的一道题重合了。都是对字符串进行编辑来进行变化。
这两个题长得太像了,前者就是个普通的计数,后者就得dp。完全是两个概念的。刚一看到题,我还想今天说要降难度,咋一上来就整个这。
import java.util.*;class q{q(){Scanner scanner=new Scanner(System.in);int n=scanner.nextInt();int m=scanner.nextInt();char[] s1=scanner.next().toCharArray();char[] s2=scanner.next().toCharArray();int times=Math.abs(n-m);int k=Math.min(n,m);for(int i=0;i<k;i++){if(s1[i]!=s2[i])times++;}System.out.println(times);}}public class Main { public static void main(String[] args) {new q(); }}
B、牛牛战队的比赛地
一开始没理解这个题啥意思,后来知道他的意思是取能令其考试地点到其所有培训基地最小的横坐标。
有点意思。
import java.util.*;class q {private double[][] k;private int n;private double length(double x){double max=0.0;for(int i=0;i<n;i++)max=Math.max(max,k[i][0]-x)*(k[i][0]-x)+k[i][1]*k[i][1]);return max;}q() {Scanner scanner=new Scanner(System.in);n=scanner.nextInt();k=new double[n][2];double left=999999.0;double right=-999999.0;for(int i=0;i<n;i++){k[i][0]=scanner.nextDouble();k[i][1]=scanner.nextDouble();if(left>k[i][0])left=k[i][0];if(right<k[i][0])right=k[i][0];}double midl,midr;for(int i=0;i<100;i++){midl=(left+left+right)/3;midr=(left+right+right)/3;if(length(midl)>length(midr)) left=midl;else right=midr;}System.out.println(Math.pow(length(left),0.5));}}public class Main {public static void main(String[] args) {new q();}}
C、C语言IDE
这道题的意思很好想,理解起来不难。就是代码奇丑无比。这里我贴上官方题解。
#include <bits/stdc++.h>using namespace std;string source;void replaceAll(string &s, string oldstr, string newstr){for (string::size_type pos = 0; pos != string::npos; pos += newstr.length())if ((pos = s.find(oldstr, pos)) != string::npos) s.replace(pos, oldstr.length(), newstr);else break;}struct functions{string inClass, name, outputType;vector<string> inputType;functions(string inClass = "", string name = "", string outputType = "void", vector<string> inputType = vector<string>(0)):inClass(inClass), name(name), outputType(outputType), inputType(inputType) {}};vector<functions> funs;void solve(string &s){replaceAll(s, "/*", " /* ");replaceAll(s, "*/", " */ ");replaceAll(s, "//", " // ");replaceAll(s, "(", " ( ");replaceAll(s, ")", " ) ");replaceAll(s, "{", " { ");replaceAll(s, "}", " } ");replaceAll(s, "=", " = ");replaceAll(s, "\"", " \" ");replaceAll(s, "'", " ' ");replaceAll(s, ";", " ; ");replaceAll(s, ",", " , ");replaceAll(s, "+ = ", "+=");replaceAll(s, "- = ", "-=");replaceAll(s, "* = ", "*=");replaceAll(s, "/ = ", "/=");replaceAll(s, "^ = ", "^=");replaceAll(s, "| = ", "|=");replaceAll(s, "& = ", "&=");replaceAll(s, ":", " : ");replaceAll(s, " : : ", "::");vector<string> tokens; string now = "";for (int i = 0; s[i]; i++){if (s[i] == ' ' || s[i] == '\t' || s[i] == '\r' || s[i] == '\n' || s[i] == '\0'){if (now != ""){if (now == ":" && tokens.back() == ")"){string tmpnow = "";for (int j = i + 1; s[j]; j++){if (s[j] == ' ' || s[j] == '\t' || s[j] == '\r' || s[j] == '\n' || s[j] == '\0'){if (tmpnow == "{"){now = "{";i = j - 1;break;}tmpnow = "";}else tmpnow += s[j];}continue;}if (now == "const"){now = "";continue;}if (now == "//"){for (int j = i; s[j]; j++){if (s[j] == '\n'){i = j - 1;break;}}now = "";continue;}if (now == "/*"){int num = 1;string tmpnow = "";for (int j = i + 1; s[j]; j++){if (s[j] == ' ' || s[j] == '\t' || s[j] == '\r' || s[j] == '\n' || s[j] == '\0'){if (tmpnow == "/*") num++;if (tmpnow == "*/"){num--;if (num == 0){i = j - 1;break;}}tmpnow = "";}else tmpnow += s[j];}now = "";continue;}//cout << now << s[i];tokens.push_back(now);now = "";}//else cout << s[i];}else now += s[i];}int cnt = 0;string nowNamespace = "";for (int i = 1; i < (int)tokens.size(); i++){if ((tokens[i] == "struct" || tokens[i] == "class") && tokens[i + 2] == "{"){cnt = 0;nowNamespace = tokens[i + 1];i += 2;}functions tmp(nowNamespace);if (tokens[i] == "{" && tokens[i - 1] == ")"){int num = 1;for (int j = i - 2; j >= 0; j--){if (tokens[j] == ")") num++;if (tokens[j] == "("){num--;if (num == 0){tmp.name = tokens[j - 1];tmp.outputType = "";for (int k = j - 2; k >= 0; k--)if (tokens[k] != "}" && tokens[k] != "}" && tokens[k] != ";" &&tokens[k].back() != ':' && tokens[k] != "inline" &&tokens[k] != "static" && tokens[k][0] != '#' &&tokens[k].back() != '\"' && tokens[k].back() != '>')tmp.outputType = tmp.outputType == "" ? tokens[k] : tokens[k] + " " + tmp.outputType;else break;int last = i - 2;for (int k = i - 2; k >= j; k--){if (tokens[k] == "(" || tokens[k] == ","){string tt = "";for (int t = k + 1; t < last; t++)tt = tt == "" ? tokens[t] : tt + " " + tokens[t];if (tt != "") tmp.inputType.push_back(tt);last = k - 1;}if (tokens[k] == "=" || tokens[k] == ")") last = k - 1;}reverse(tmp.inputType.begin(), tmp.inputType.end());break;}}}funs.push_back(tmp);num = 1;for (int j = i + 1; j < (int)tokens.size(); j++){if (tokens[j] == "{") num++;if (tokens[j] == "}"){num--;if (num == 0){i = j;//cout << tmp.outputType << " " << tmp.name << " ";//cout << j << endl;break;}}}continue;}if (nowNamespace != ""){//cout << i << " " << nowNamespace << " " << cnt << endl;if (tokens[i] == "{") cnt++;if (tokens[i] == "}"){cnt--;if (!cnt) nowNamespace = "";}}}}int main(){char ch;while ((ch = getchar()) != EOF)source += ch;solve(source);for (auto & i: funs){if (i.outputType != "") cout << i.outputType << " ";if (i.inClass != "") cout << i.inClass << "::";cout << i.name << "(";for (int j = 0; j < (int)i.inputType.size(); j++)cout << i.inputType[j] << (j == (int)i.inputType.size() - 1 ? ")" : ",");if ((int)i.inputType.size() == 0) cout << ")";cout << endl;}return 0;}
D、牛牛与牛妹的约会
嘤嘤嘤,题目跟我秀恩爱可还行。一道典型的贪心题目。
#include<bits/stdc++.h>using namespace std;int main(void){int T; cin>>T;while(T--){int a, b; scanf("%d%d", &a, &b);double ans = 0;double ca = a, cb = b;double p = 1.0/3.0;while(1){double na;if(ca < 0) na = -pow(-ca,p);else na = pow(ca, p);if(abs(na-cb)+1.0 < abs(ca-cb)) ans += 1.0, ca = na;else {ans += abs(ca-cb); break;}}printf("%.9f\n", ans);}return 0;}
E、Enjoy the game
又是一道水题。
这个题看上去挺别扭,其实就是个判断是不是二的倍数。具体流程如下:
这里假定一共 张牌
1、看看 是不是奇数,如果是,那么先手必胜。
2、若 为偶数,那么此时先手应当出偶数个,不然轮到对方时,就成了对方的奇数先手。
3、同理,对方也应当出偶数。这样的话看来,若我们假定双方出的偶数都为2,那么当为奇数时,先手必胜。
4,把,然后在回到步骤2,直到最后可以获得一个不为1的奇数时,可以判断先手必胜,若为1,那么先手必输。
至于为什么当最后为1时就不行…….因为这个数你如果为1的话,从你计算的时候的意义上来看,是你必须在第一次时就拿走所有的牌你才能赢。但这很明显不合题意,所以不行。
import java.util.*;class q{private boolean ok(long k){if(k==1)return false;if(k%2==1)return true;else return ok(k/2);}q(){Scanner scanner=new Scanner(System.in);long k=scanner.nextLong();System.out.println(ok(k)?"Bob":"Alice");}}public class Main { public static void main(String[] args) {new q(); }}
F、碎碎念
G、街机争霸
H、Hash
I、I题是个签到题
啊,顾名思义,这的确是个签到题。
说白了就是在读取的时候,实时维护整个数据里头前三大的数。然后在最后再判定一下是不是人数大于所有人的。没了,就这,贼水。
import java.util.*;class q {private ArrayList<Integer> k = new ArrayList<>(3);private int where(int qqq) {int i=k.size();if(i==0||k.get(0)<=qqq)return 0;if(i==1||k.get(1)<=qqq)return 1;if(i==2||k.get(2)<=qqq)return 2;else return 3;}q() {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();double m = scanner.nextInt();int kkk = 0;boolean ok=false;for (int i = 0; i < n; i++) {int o = scanner.nextInt();if(i==8)kkk=o;int s=where(o);if(s<3){if(k.size()==3)k.remove(2);k.add(s,o);}}double ppp=kkk/m;if(k.indexOf(kkk)!=-1)ok=true;if(ppp>=0.8)ok=true;System.out.println(ok?"Yes":"No");}}public class Main {public static void main(String[] args) {new q();}}
J、牛牛战队的秀场
这是个数学题…..上过初中的就会……
根据给的,先选出来劣弧是哪一段,然后再得到我们要求的长度应为
。然后写式子就可以了。
import java.util.*;class q{q(){Scanner scanner=new Scanner(System.in);double n=scanner.nextInt();double r=scanner.nextInt();int i=scanner.nextInt();int j=scanner.nextInt();double l=2* r *Math.sin(Math.PI/n);if(i>j){if(j+n-i>i-j) System.out.printf("%.6f",(i-j)*l);else System.out.printf("%.6f",(j+n-i)*l);}else {if(i+n-j>j-i) System.out.printf("%.6f",(j-i)*l);else System.out.printf("%.6f",(i+n-j)*l);}}}public class Main { public static void main(String[] args) {new q(); }}
