Jam的计数法


1 //二进制相关
2 #include<bits/stdc++.h>
3 #define ll long long
4 using namespace std;
5 inline ll fast_read()
6 {
7 char c = getchar();
8 ll a = 0;
9 int k = 0;
10 while(!isdigit(c))
11 {
12 if(c == '-') k = 1;
13 c = getchar();
14 }
15 while(isdigit(c)) a = (a << 3) + (a << 1) + c - '0' , c = getchar();
16 return k ? -a : a;
17 }
18 inline void fast_print(ll x)
19 {
20 int num[1001] , dirN = -1;
21 if(x < 0) putchar('-') , x = -x;
22 while(x) num[++dirN] = x % 10 , x /= 10;
23 if(dirN == -1) putchar('0');
24 while(dirN + 1) putchar(num[dirN--] + 48);
25 }
26 int main()
27 {
28 ll a = fast_read() , b = fast_read() , sum = 0 , d = 1;
29 while(b)
30 {
31 if(b & 1) sum += d;
32 b >>= 1;
33 d *= a;
34 }
35 fast_print(sum);
36 return 0;
37 }
数列


1 //结构体排序
2 #include<bits/stdc++.h>
3 using namespace std;
4 struct stu{
5 int chi , math , eng , tot , i;
6 inline void input()
7 {
8 cin >> chi >> math >> eng;
9 tot = chi + math + eng;
10 }
11 }ans[301];
12 bool cmp(stu a , stu b)
13 {
14 return a.tot > b.tot || a.tot == b.tot && a.chi > b.chi || a.tot == b.tot && a.chi == b.chi && a.i < b.i;
15 }
16 int main()
17 {
18 int n;
19 cin >> n;
20 for(int i = 0 ; i < n ; i++)
21 {
22 ans[i].input();
23 ans[i].i = i + 1;
24 }
25 sort(ans , ans + n , cmp);
26 for(int i = 0 ; i < 5 ; i++)
27 cout << ans[i].i << " " << ans[i].tot << endl;
28 return 0;
29 }
奖学金


1 //贪心选能够搭配的最大的
2 #include<bits/stdc++.h>
3 using namespace std;
4 int num[30001];
5 int main()
6 {
7 ios::sync_with_stdio(false);
8 int n , k , m = 0 , cou = 0;
9 cin >> n >> k;
10 for(int i = 0 ; i < k ; i++) cin >> num[i];
11 sort(num , num + --k + 1);
12 while(m <= k)
13 {
14 cou++;
15 int sum = num[k--];
16 while(sum + num[m] <= n && m <= k) sum += num[m++];
17 }
18 cout << cou;
19 return 0;
20 }
纪念品分组


1 //条件判断练习题
2 #include<bits/stdc++.h>
3 #define ll long long
4 using namespace std;
5 inline ll fast_read()
6 {
7 char c = getchar();
8 ll a = 0;
9 int k = 0;
10 while(!isdigit(c))
11 {
12 if(c == '-') k = 1;
13 c = getchar();
14 }
15 while(isdigit(c)) a = (a << 3) + (a << 1) + c - '0' , c = getchar();
16 return k ? -a : a;
17 }
18 int main()
19 {
20 int M = fast_read() , S = fast_read() , T = fast_read() , t , s;
21 if(M / 10 * 60 >= S)
22 if(ceil(S / 60.0) > T) cout << "No" << endl << T * 60;
23 else cout << "Yes" << endl << (int)ceil(S / 60.0);
24 else if(M / 10 >= T) cout << "No" << endl << T * 60;
25 else{
26 t = M / 10;
27 s = M / 10 * 60;
28 M %= 10;
29 while(s < S && T > t && M >= 2 && T - t >= ceil((14 - M) / 4.0))
30 {
31 if(M < 10) M += 4;
32 else{
33 M -= 10;
34 s += 60;
35 }
36 t++;
37 }
38 while(s < S && T > t)
39 if(T - t >= ceil((28 - M) / 4.0) && S - s >= 120)
40 {
41 t += ceil((28 - M) / 4.0);
42 s += 120;
43 }
44 else
45 {
46 if(T - t >= ceil((14 - M) / 4.0) && ceil((14 - M) / 4.0) * 17 < 60 && S - s > ceil((14 - M) / 4.0) * 17)
47 {
48 t += ceil((14 - M) / 4.0);
49 s += 60;
50 }
51 while(s < S && T > t++) s += 17;
52 }
53 if(s >= S) cout << "Yes" << endl << t;
54 else cout << "No" << endl << s;
55 }
56 return 0;
57 }
守望者的逃离


1 //递推
2 #include<bits/stdc++.h>
3 #define ll long long
4 using namespace std;
5 inline ll fast_read()
6 {
7 char c = getchar();
8 ll a = 0;
9 int k = 0;
10 while(!isdigit(c))
11 {
12 if(c == '-') k = 1;
13 c = getchar();
14 }
15 while(isdigit(c)) a = (a << 3) + (a << 1) + c - '0' , c = getchar();
16 return k ? -a : a;
17 }
18 inline void fast_print(ll x)
19 {
20 int num[1001] , dirN = -1;
21 if(x < 0) putchar('-') , x = -x;
22 while(x) num[++dirN] = x % 10 , x /= 10;
23 if(dirN == -1) putchar('0');
24 while(dirN + 1) putchar(num[dirN--] + 48);
25 }
26 int num[201][999];
27 int main()
28 {
29 int a = fast_read();
30 for(int i = 1 ; i <= a ; i++)
31 {
32 num[i][0] = num[i - 1][0] + 1;
33 num[i][1] = 2;
34 for(int j = 1 ; j <= num[i - 1][0] ; j++)
35 {
36 num[i][j] += num[i - 1][j] * 2;
37 if(num[i][j] >= 10)
38 {
39 num[i][j + 1]++;
40 num[i][j] -= 10;
41 }
42 }
43 if(!num[i][num[i][0]]) num[i][0]--;
44 }
45 for(int i = num[a][0] ; i ; i--)
46 fast_print(num[a][i]);
47 return 0;
48 }
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-124192-4.html
听话的话大家都好
好想去
不清楚生产环境和流程