Forsaken喜欢数论

思路:想到了用欧拉函数但是开始时没想到欧拉函数的原理就是质因数,浪费了时间,其中还有一些差错:例如以为到3e7最多724个,sqrt(30000000<(5478)导致for循环范围开小,以及数组开小,到最后改完交c++11交超时,过90%的数据,以为是cin的输入问题,还是wa,改成c++14交A了

 1 #include <iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 #include<string.h>
 6 #include<map>
 7 #include<queue>
 8 #include<vector>
 9 #include<string>
10 #include<time.h>
11 using namespace std;
12 #define N 30000010
13 int vis[N] = { 0 };
14 int cnt = 0;
15 int n;
16 long long prime[N];
17 long long  ans=0;
18 void prim()
19 {
20     for (int i = 2; i <= n; i++)
21     {
22         if (!vis[i])
23         {
24             prime[cnt++] = i;
25             ans += i;
26         }
27         for (int j = 0; j < cnt&&i*prime[j] <= n; j++)
28         {
29             vis[i*prime[j]] = 1;
30             ans += prime[j];
31             if (i%prime[j] == 0)
32                 break;
33         }
34     }
35     printf("%lld", ans);
36 }
37 int main()
38 {
39     scanf("%d", &n);
40     prim();
41     return 0;
42 }

Forsaken给学生分组

题解:用sort排序,尾减头就ok

 1 #include <iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 #include<string.h>
 6 #include<map>
 7 #include<queue>
 8 #include<vector>
 9 #include<string>
10 #include<time.h>
11 using namespace std;
12 long long ans= 0;
13 int a[100010];
14 int main()
15 {
16     int n,k;
17     cin >> n >> k;
18     for (int i = 0; i < n; i++)
19         cin >> a[i];
20     sort(a, a + n);
21     int l = 0, r = n - 1;
22     while (k--)
23     {
24         ans += a[r--] - a[l++];
25     }
26     cout << ans << endl;
27     return 0;
28 }

 Forsaken喜欢正方形

题意:注意点没有重复的,且只能改变一个点,所以可以任取两个点进行判断与剩下的两个点的距离相等

 1 #include <iostream>
 2 #include<algorithm>
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 #include<string.h>
 6 #include<map>
 7 #include<queue>
 8 #include<vector>
 9 #include<string>
10 #include<time.h>
11 using namespace std;
12 struct node
13 {
14     int x, y;
15 }aa,bb,cc,dd,so[7];
16 vector<node>a, b, c, d;
17 int len(node a, node b)
18 {
19     int x = (a.x - b.x)*(a.x - b.x);
20     int y = (a.y - b.y)*(a.y - b.y);
21     return x + y;
22 }
23 int squre(node a, node b, node c, node d)
24 {
25     int flag = 0;
26     if (len(a, b) == len(d, c) && len(a, c) == len(b, d) && len(a, d) == len(b, c))
27         flag = 1;
28     return flag;
29 }
30 int t = 0;
31 void Dfs(node a, node b, node c, node d)
32 {
33     so[1] = a; so[2] = b; so[3] = c; so[4] = d;
34     for (int i = 1; i <= 4; i++)
35     {
36         so[i].x -= 1;
37         if (squre(so[1], so[2], so[3], so[4]))
38             t = 1;
39         so[i].x += 2;
40         if (squre(so[1], so[2], so[3], so[4]))
41             t = 1;
42         so[i].x -= 1;
43     }
44     for (int i = 1; i <= 4; i++)
45     {
46         so[i].y -= 1;
47         if (squre(so[1], so[2], so[3], so[4]))
48             t = 1;
49         so[i].y += 2;
50         if (squre(so[1], so[2], so[3], so[4]))
51             t = 1;
52         so[i].y -= 1;
53     }
54 }
55 int main()
56 {
57     cin >> aa.x >> aa.y;
58     cin >> bb.x >> bb.y;
59     cin >> cc.x >> cc.y;
60     cin >> dd.x >> dd.y;
61     if (squre(aa,bb,cc,dd))
62     {
63         cout << "wen" << endl;
64         return 0;
65     }
66     Dfs(aa, bb, cc, dd);
67     if (t == 1)
68     {
69         cout << "hai xing" << endl;
70         return 0;
71     }
72     cout << "wo jue de bu xing" << endl;
73     return 0;
74 }
01-04 16:35
查看更多