c multimap_emacs python c-c c-c i 不好使_a=b=c,a=b==c c语言(9)

电脑杂谈  发布时间:2019-09-26 07:03:00  来源:网络整理

文化之旅

 1 //数位DP(划掉
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 inline int cou(int a , int b)
 5 {
 6     int sum = 0;
 7     while(a)
 8     {
 9         if(a % 10 == b)    sum++;
10         a /= 10;
11     }
12     return sum;
13 }
14 int main()
15 {
16     int a , b , sum = 0;
17     cin >> a >> b;
18     for(int i = 1 ; i <= a ; i++)    sum += cou(i , b);
19     cout << sum;
20     return 0;
21 }

计数问题

 1 //栈
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 string s;
 5 int num[100001];
 6 char op[100001];
 7 int main()
 8 {
 9     cin >> s;
10     s += '@';
11      int nowN = 0 , head = 0;
12     for(int i = 0 ; i < s.size() ; i++)
13          if(isdigit(s[i]))
14              nowN = (nowN * 10 + s[i] - 48) % 10000;
15          else{
16              num[head] = nowN;
17              nowN = 0;
18              if(head && op[head - 1] == '*'){
19                  num[head - 1] = num[head - 1] * num[head] % 10000;
20                  head--;
21             }
22              op[head++] = s[i];
23          }
24      for(int i = 1 ; i < head ; i++)
25          num[0] = (num[0] + num[i]) % 10000;
26      cout << num[0];
27     return 0;
28 }

表达式求值

 1 //贪心+DP
 2 #include<bits/stdc++.h>
 3 #define ll __int128
 4 //This code is written by Itst
 5 using namespace std;
 6 
 7 inline int read(){
 8     int a = 0;
 9     bool f = 0;
10     char c = getchar();
11     while(c != EOF && !isdigit(c)){
12         if(c == '-')
13             f = 1;
14         c = getchar();
15     }
16     while(c != EOF && isdigit(c)){
17         a = (a << 3) + (a << 1) + (c ^ '0');
18         c = getchar();
19     }
20     return f ? -a : a;
21 }
22 
23 const int MAXN = 1000010;
24 ll sum[MAXN] , spe[MAXN] , sco[MAXN] , maxSco , minN , maxN , maxSCO , N;
25 
26 int main(){
27 #ifdef OJ
28     freopen("1982.in" , "r" , stdin);
29     //freopen("1982.out" , "w" , stdout);
30 #endif
31     N = read();
32     int P = read();
33     spe[0] = -1ll << 62;
34     for(int i = 1 ; i <= N ; i++){
35         sum[i] = sum[i - 1] + read();
36         spe[i] = max(spe[i - 1] , sum[i] - minN);
37         minN = min(minN , sum[i]);
38     }
39     maxSCO = sco[1] = spe[1];
40     maxN = sco[1] + spe[1];
41     for(int i = 2 ; i <= N ; i++){
42         sco[i] = maxN;
43         maxSCO = max(maxSCO , sco[i]);
44         maxN = max(maxN , sco[i] + spe[i]);
45     }
46     cout << (int)(maxSCO % P);
47     return 0;
48 }

小朋友的数字

 1 //拓扑排序+(可能的)优化连边
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 inline int read(){
 5     int a = 0;
 6     char c = getchar();
 7     while(!isdigit(c))    c = getchar();
 8     while(isdigit(c))    a = (a << 3) + (a << 1) + (c ^ '0') , c = getchar();
 9     return a;
10 }
11 inline int max(int a , int b){
12     return a > b ? a : b;
13 }
14 vector < int > Ed[1001];
15 int in[1001] , maxN[1001];
16 bool vis[1001][1001];
17 int main(){
18     int n = read() , m = read() , Max = 1;
19     while(m--){
20         int k = read() , bef;
21         vector < int > s , g;
22         s.push_back(bef = read());
23         for(int i = 1 ; i ^ k ; i++){
24             int a = read(); 
25             while(++bef ^ a){
26                 g.push_back(bef);
27                 for(int j = 0 ; j ^ i ; j++)
28                     if(!vis[bef][s[j]]){
29                         vis[bef][s[j]] = vis[s[j]][bef] = 1;
30                         Ed[bef].push_back(s[j]);
31                         in[s[j]]++;
32                     }
33             } 
34             s.push_back(bef);
35             a = g.size();
36             for(int j = 0 ; j ^ a ; j++)
37                 if(!vis[g[j]][bef])
38                 {
39                     vis[g[j]][bef] = vis[bef][g[j]] = 1; 
40                     Ed[g[j]].push_back(bef);
41                     in[bef]++;
42                 }
43         }
44     }
45     queue < int > q;
46     for(int i = 1 ; i <= n ; i++)
47         if(!in[i]){
48             maxN[i] = 1;
49             q.push(i);
50         }
51     while(!q.empty()){
52         int t = q.front();
53         q.pop();
54         Max = max(Max , maxN[t]);
55         for(int i = 0 ; i < Ed[t].size() ; i++)
56             if(!--in[Ed[t][i]]){
57                 maxN[Ed[t][i]] = maxN[t] + 1;
58                 q.push(Ed[t][i]);
59             }
60     }
61     cout << Max;
62     return 0;
63 }

*车站分级

 1 //枚举分母,找最靠近给出条件的分子
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int main()
 5 {
 6     int A , B , L , ansA = 0 , ansB;
 7     cin >> A >> B >> L;
 8     for(int i = 1 ; i <= L ; i++){
 9         int t = A * i / B;
10         if(t > L)
11             break;
12         if(t * B == A * i){
13             cout << t << ' ' << i;
14             return 0;
15         }
16         t++;
17         if(t > L)
18             break;
19         if(!ansA){
20             ansA = t;
21             ansB = i;
22         }
23         else
24             if(ansA * i > ansB * t){
25                 ansA = t;
26                 ansB = i;
27             }
28     }
29     cout << ansA << ' ' << ansB;
30       return 0;
31 }


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-124192-9.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...