2019 cattle off the National Day party training day1 (A, BEFK)

Links: https://ac.nowcoder.com/acm/contest/1099#question

A: FIG intermediate understood there must meet the requirements of a configuration of a rectangle, to find a boundary of a rectangular configuration, a quantity of occurrence is determined equal to the area of ​​the rectangle.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char a[15][15];
 4 int main()
 5 {
 6     int n, m;
 7     while(cin >> n >> m)
 8     {
 9         int x1 = 100, x2 = 0;
10         int y1 = 100, y2 = 0;
11         int cnt = 0;
12         for(int i = 0;i < n;i++)
13             for(int j = 0;j < m;j++)
14                 cin >> a[i][j];
15         for(int i = 0;i < n;i++)
16             for(int j = 0;j < m;j++)
17                 if(a[i][j] == '1'){
18                     cnt++;
19                     x1 = min(x1, i);
20                     x2 = max(x2, i);
21                     y1 = min(y1, j);
22                     y2 = max(y2, j);
23                 }
24         if((x2 - x1 + 1)*(y2 - y1 + 1) == cnt) cout << "Yes" << endl;
25         else cout << "No" << endl;
26     }
27     return 0;
28 }
View Code

B: Title given formula is a combination of the number of formula C (n, k), is a function of the number of opening combinations downward quadratic function, so the symmetry, can be monotonically increasing on one side, we can from C (n, 0) has been enumerated to C (n, min (k, n - k)); and the more than 1e18 out.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll INF = 1e18;
 5 ll n, k;
 6 void yf(ll &a, ll &b){
 7     ll d = __gcd(a, b);
 8     a /= d;
 9     b /= d;
10 }
11 int main()
12 {
13     std::ios::sync_with_stdio(false);
14     while(cin >> n >> k)
15     {
16         bool flag = false;
17         k = min(k, n - k);
18         ll cnt = n;
19         ll sum = 1;
20         ll last = 1;
21         for(ll i = 1;i <= k;i++){
22             ll t1 = cnt--;
23             ll t2 = i;
24             yf(t1, t2);
25             yf(t1, last);
26             yf(sum, t2);
27             sum *= t1;
28             last *= t2;
29             yf(sum, last);
30             if(sum / last >= INF ){
31                 cout << INF << endl;
32                 flag = true;
33                 break;
34             }
35         }
36         if(!flag)
37         cout << sum << endl;
38     }
39 
40     return 0;
41 }
View Code

 E: memory search.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 string a;
 4 int ans;
 5 int vis[105];
 6 void dfs(int now){
 7     if(now >= a.size())
 8     {
 9         ans++;
10         return;
11     }
12     int t = a[now] - '0';
13     if(!vis[t]){
14         vis[t] = 1;
15         dfs(now + 1);
16         vis[t] = 0;
17     }
18     if(a[now]- '0' != 0 && now + 1 < a.size()){
19         int tmp = t * 10 + a[now + 1] - '0';
20         if(!vis[tmp]){
21             vis[tmp] = 1;
22             dfs(now + 2);
23             vis[tmp] = 0;
24         }
25     }
26 
27 }
28 int main()
29 {
30 
31     std::ios::sync_with_stdio(false);
32     while(cin >> a){
33         ans = 0;
34         dfs(0);
35         cout << ans << endl;
36     }
37 
38 }
View Code

 F: meaning of the questions: Bobo beginning at the origin (0,0) on a plane, there are four operations: a step up moves to the right, up to the upward movement step b, step c moves to the left most, a maximum downward movement step d . Q n times the number of different operating points can be reached.

Thinking: operation only a very simple step, respectively, you can reach the coordinate axis away from the origin (a, 0), (0It contains an origin including a total of 1 + a + b + c +points.

Multi-step, we first look at the situation in the first quadrant:

The first operation reaches the x-axis interval [1, a], the 2nd to n-th in the vertical direction to reach [1, (n-1) b)], a total of a * (n-1) b th point;

Two x-axis operation reaches the interval [a + 1, 2a], the 2nd to n-th in the vertical direction to reach [1, (n-2) b)], a total of a * (n-2) b points;

···

n-1 operations reaches the x-axis interval [(n-2) a + 1, (n-1) a], on the first n 1-th to n-th in the vertical direction to reach [1, b], a total of // two points a * b;

a point operations // n reaches the x-axis furthest [(n-1) * a + 1, na].

So the answer is simple, 1 + n * (a + b + c + d) + n (n-1) / 2 * (ab + bc + cd + ad).

Reference blog: https://www.cnblogs.com/izcat/p/11618652.html

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int mod = 1e9+7;
 5 int main()
 6 {
 7     ll n, a, b, c, d;
 8     while(cin >> n >> a >> b >> c >> d)
 9     {
10         ll ans = 1LL + (a + b + c + d) % mod * n % mod + n * (n - 1) / 2 % mod*((a * b % mod+ b * c % mod + c * d % mod + a * d % mod) % mod) % mod;
11         cout << ans % mod << endl;
12     }
13     return 0;
14 }
View Code

K: Analog list, learn how to write big brother, only 40 lines of code, handwritten list write their own vomit also the WA

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5+5;
 4 int n,m,x,y;
 5 list <int> L[maxn],D[maxn];//L为正序, D为L的倒序
 6 int main()
 7 {
 8     while(cin >> n >> m)
 9     {
10         for(int i = 1;i <= n;i++)
11         {
12             L[i].clear(),L[i].push_back(i);
13             D [I] .clear (), D [I] .push_back (I);
 14          }
 15          the while (M-- )
 16          {
 . 17              CIN >> >> X Y;
 18 is              D [Y] .splice (D [Y ] .end (), D [x]); // will reverse back stitching in the y-x 
. 19              L [x] .splice (L [x] .end (), L [y]); // x and y positive sequence splice 
20 is              the swap (L [x], D [y]); // reverse y becomes positive sequence of x 
21 is              the swap (D [x], D [y]); // positive sequence becomes x, x reverse 
22 is              L [Y] .clear ();
 23 is              D [Y] .clear ();
 24          }
 25         cout << L[1].size();
26         for(auto it:L[1]) cout << " " << it;
27         cout << endl;
28     }
29     return 0;
30 }
View Code

 

Guess you like

Origin www.cnblogs.com/Carered/p/11618382.html