不是题解 只是简单的记录下自己写过的东西~~
第一题其实主要是看你阅读水平的
给你一堆点 然后问你能不能删掉一个点然后使其余所有的点都在Y轴的一侧 很简单对吧~~
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int _ , Left , Right, x , y ;
Left = Right = 0;
cin >>_;
while (_ --) {
cin >> x >> y;
if (x > 0) Right ++;
else Left ++;
}
if (Left <= 1 || Right <= 1) cout << "Yes" << endl;
else cout << "No" << endl;
}
第二题就比较有意思了
大概意思是这样的 给你三个数字 a b c 问你a除以b的小数部分第几位是c 如果没有 就输出-1
当时我没有想到模拟小学生除法的这种思想 但是水过去了
做法很多 找寻环节如果没找到就GG 对吧 但是找的过程中有一个鸽巢原理循环节不可能比本身还长 所以复杂度O(b)
这是出题人给的题解:
In this task you should complete long division and stop, when one period passed. Period can't be more than b by pigeonhole principle. So you need to complete b iterations and if c digit hasn't been met, print - 1.
Time complexity O(b).
我比赛时候的过法就比较神奇了:
java 大小数三百位暴力找 没有就GG
先帖一个我的非主流过法:
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) throws Exception {
Scanner stdin = new Scanner(System.in);
double a , b;
// a = a - int(a / b) * b;
Integer k;
a = stdin.nextDouble();
b = stdin.nextDouble();
k = stdin.nextInt();
BigDecimal aa = new BigDecimal(Double.toString(a));
BigDecimal bb = new BigDecimal(Double.toString(b));
String str = aa.divide(bb , 300, BigDecimal.ROUND_HALF_UP).toString();
boolean flag = true;
// System.out.println(str);
int Ca = 1;
for (int i = 2; i < 300; i ++) {
String temp = String.valueOf(k);
String tt = String.valueOf(str.charAt(i));
// System.out.println("temp == " + temp + "tt == " +tt);
// System.out.println("temp == " + str.charAt(i));
if (temp.equals(tt)) {
System.out.println(Ca);
flag = false;break;
}
Ca = Ca + 1;
}
if (flag == true) System.out.println(-1);
}
}
然后贴 个我模拟小学生除法过的代码:
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100005;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int a , b , c, temp, Case = 0;
cin >> a >> b >> c;
temp = a;
memset(idx , false , sizeof(N));
while (Case < 100000) {
Case++;
temp *= 10;
int cur = temp / b;
temp %= b;
if (cur == c) {
cout << Case <<endl;return 0;
}
}
cout << -1 << endl;
}
最后也是最犀利的解法是找循环节 tie一个cf大佬的解法吧:
人家这个写的真的简洁~(毕竟红名ORZ)
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;
const int Maxn = 1000005;
int a, b, c;
bool was[Maxn];
int main()
{
cin >> a >> b >> c;
for (int i = 1; ; i++) {
a *= 10;
if (was[a]) break;
was[a] = true;
int cur = a / b; a %= b;
if (cur == c) { printf("%d\n", i); return 0; }
}
printf("-1\n");
return 0;
}
PS:写cf以来第一次+88 开心的不行 ~~