A. Dasha and Stairs

Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有b个。

Analysis:

  cj: 纸张的我=.= 经过Return改正,才发现没有主义a = b = 0的情况。

 1 #define PRON "a"
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <vector>
 5 #include <iostream>
 6 #include <algorithm>
 7 #define inf 0x3f3f3f3f
 8 #define LL "%lld"
 9 using namespace std;
10 typedef long long ll;
11 
12 int a, b;
13 
14 int main(){
15     scanf("%d %d", &a, &b);
16     if ((!a) && (!b)) { puts("NO"); return 0; } 
17     if (abs(a - b) <= 1)
18         cout << "YES";
19     else 
20         cout << "NO";
21 }
Code by Return

 

B. Dasha and friends

Problems:有无数不同的长度为l的环,上面有m个障碍。有两个人在不同的位置,给出障碍相对于自己的距离。判断两人是否在同一个环上。

Analysis:

  cj: 做个差,随便比较一下。

 1 #define PRON "b"
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <vector>
 5 #include <iostream>
 6 #include <algorithm>
 7 #define inf 0x3f3f3f3f
 8 #define LL "%lld"
 9 using namespace std;
10 typedef long long ll;
11 
12 const int maxn = 100 + 10;
13 
14 int n, l, a[maxn], b[maxn], c[maxn], d[maxn];
15 
16 bool ok(int x){
17     for (int i = 0, j = x; i < n; i ++, j ++){
18         if (j == n)
19             j = 0;
20         if (c[i] != d[j])
21             return false;
22     }
23 
24     return true;
25 }
26 
27 bool check(){
28     for (int i = 0; i < n; i ++)
29             if (c[0] == d[i] && ok(i))
30                 return true;
31     return false;
32 }
33 
34 int main(){
35 #ifndef ONLINE_JUDGE
36     freopen(PRON ".in", "r", stdin);
37 #endif
38 
39     cin >> n >> l;
40     for (int i = 0; i < n; i ++){
41         cin >> a[i];
42         if (i)
43             c[i] = a[i] - a[i - 1];
44     }
45     c[0] = a[0] + l - a[n - 1];
46     for (int i = 0; i < n; i ++){
47         cin >> b[i];
48         if (i)
49             d[i] = b[i] - b[i - 1];
50     }
51     d[0] = b[0] + l - b[n - 1];
52 
53     if (check())
54         cout << "YES";
55     else 
56         cout << "NO";
57 }
Code by cj

 

C. Dasha and Password

Problems:一个合格的密码需要有至少一个字母、至少一个数字、至少一个特殊字符(* # &)。有n个字符串,光标都在第一个字母处。(光标在最左向右移动就到最右)求最少的光标移动操作,使得光标所选中的字母能构成一个合格的密码。

 

Analysis:

 

  cj: 对于每个字符串求出最近的字母、数字、特殊字符的最小操作。数据范围小,直接for一下就好。

 1 #define PRON "c"
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <vector>
 5 #include <iostream>
 6 #include <algorithm>
 7 #define inf 0x3f3f3f3f
 8 #define LL "%lld"
 9 #define ed second
10 #define st first
11 using namespace std;
12 typedef long long ll;
13 
14 const int maxn =  50 + 10;
15 
16 int n, len;
17 pair<int, int> dig[maxn], sy[maxn], l[maxn];
18 string s;
19 
20 int get_ans(){
21     int ans = inf;
22     for (int i = 0; i < n; i ++)
23         for (int j = 0; j < n; j ++)
24             for (int k = 0; k < n; k ++){
25                 if (sy[i].ed != l[j].ed && l[j].ed != dig[k].ed && dig[k].ed != sy[i].ed){
26                     if (~sy[i].st && ~l[j].st && ~dig[k].st)
27                         ans = min(sy[i].st + l[j].st + dig[k].st, ans);
28                 }
29             }
30     return ans;
31 }
32 
33 inline bool is_dig(char c){
34     return '0' <= c && c <= '9';
35 }
36 
37 inline bool is_sy(char c){
38     return c == '#' || c == '*' || c == '&';
39 }
40 
41 inline bool is_l(char c){
42     return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
43 }
44 
45 int main(){
46 #ifndef ONLINE_JUDGE
47     freopen(PRON ".in", "r", stdin);
48 #endif
49 
50     cin >> n >> len;
51     for (int i = 0; i < n; i ++){
52         cin >> s;
53 
54         s[len] = '\0';
55         dig[i].st = sy[i].st = l[i].st = -1;
56         dig[i].ed = sy[i].ed = l[i].ed = i;
57         for (int j = 0, k = len; j <= k; j ++, k --){
58             if (l[i].st == -1 && (is_l(s[j]) || is_l(s[k])))
59                 l[i].st = j;
60             if (dig[i].st == -1  && (is_dig(s[j]) || is_dig(s[k])))
61                 dig[i].st = j;
62             if (sy[i].st == -1  && (is_sy(s[j]) || is_sy(s[k])))
63                 sy[i].st = j;
64             
65             if (~dig[i].st && ~sy[i].st && ~l[i].st)
66                 break;
67         }
68     }
69 
70     sort(l, l + n);
71     sort(dig, dig + n);
72     sort(sy, sy + n);
73 
74     cout << get_ans();
75 }
Code by cj

 

 

D. Dasha and Very Difficult Problem

Problems: c[i] = b[i] - a[i],给定l, r, n、数组a、数组c的大小排名,求符合条件的数组b。其中l <= a[i], b[i] <= r。

Analysis:

  return: 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 //#include<iostream>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 #include<string>
 9 #include<vector>
10 using namespace std;
11 #define INF 2000000000
12 #define Clear(x, Num) memset(x, Num, sizeof(x))
13 #define Dig(x) ((x>='0') && (x<='9'))
14 #define Neg(x) (x=='-')
15 #define G_c() getchar()
16 #define Maxn 1000010
17 typedef long long ll;
18 
19 struct Data
20 {
21     int rank, id;
22     ll l, r;
23 }c[Maxn];
24 int n;
25 ll l, r, a[Maxn], b[Maxn];
26 
27 inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
28 inline void read(int &x){ char ch; int N=1; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-1; while ((ch=G_c()) && (!Dig(ch))); } x=ch-48; while ((ch=G_c()) && (Dig(ch))) x=x*10+ch-48; x*=N; }
29 //inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; }
30 inline bool cmp(const Data &a, const Data &b) { return a.rank<b.rank; }
31 int main()
32 {
33     scanf("%d%lld%lld", &n, &l, &r);
34     for (int i=1; i<=n; i++) scanf("%lld", &a[i]);
35     for (int i=1; i<=n; i++) scanf("%d", &c[i].rank), c[i].id=i;
36     sort(c+1, c+n+1, cmp);
37     c[1].l=l-a[c[1].id]; c[1].r=r-a[c[1].id];
38     for (int i=2; i<=n; i++)
39     {
40         c[i].l=max(l-a[c[i].id], c[i-1].l+1);
41         c[i].r=min(r-a[c[i].id], c[i-1].r+1);
42         if (c[i].l>c[i].r) { puts("-1"); return 0; }
43     }
44     b[c[n].id]=c[n].l;
45     for (int i=n-1; i>=1; i--)
46     {
47         c[i].r=min(c[i].r, b[c[i+1].id]);
48         if (c[i].l>c[i].r) { puts("-1"); return 0; }
49         b[c[i].id]=c[i].l;
50     }
51     for (int i=1; i<=n; i++) printf("%lld ", b[i]+a[i]); puts("");
52 }
code by return

 

E. Dasha and Puzzle

Problems: 给一颗无根数,把它画在平面上。边长随意,边必须和坐标轴平行,边之间不能在非端点处相交。

Analysis:

  cj: 边长随意!!!n <= 30, |x|, |y| <= 1e18!!!把1当作根,dep=1时把len弄个2的很多次方,深度每+1,len就/2,这样每个点就随意能的有三个儿子。

 1 #define PRON "e"
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <vector>
 5 #include <iostream>
 6 #include <algorithm>
 7 #define inf 0x3f3f3f3f
 8 #define LL "%lld"
 9 #define st first
10 #define nd second
11 using namespace std;
12 typedef long long ll;
13 
14 #define mp make_pair
15 
16 const int maxn = 30 + 10;
17 const int ax[] = {-1, 0, 1, 0};
18 const int ay[] = {0, 1, 0, -1};
19 
20 vector<int> g[maxn]; 
21 pair<ll, ll> ans[maxn];
22 int n;
23 
24 inline void fail(){
25     printf("NO");
26     exit(0);
27 }
28 
29 void dfs(int u, int pre, ll len, int dir, ll x, ll y){
30     if (g[u].size() > 4)
31         fail();
32 
33     ans[u] = mp(x, y);
34     for (int i = 0, v, now_dir = 0; i < g[u].size(); i ++){
35         v = g[u][i];
36         if (v == pre)
37             continue;
38 
39         if (pre != 0 && (dir + 2) % 4 == now_dir)
40             now_dir ++;
41 
42         dfs(v, u, len / 2, now_dir, x + len * (ll)ax[now_dir], y + len * (ll)ay[now_dir]);
43         now_dir ++;
44     }
45 }
46 
47 
48 int main(){
49 #ifndef ONLINE_JUDGE
50     freopen(PRON ".in", "r", stdin);
51 #endif
52 
53     cin >> n;
54     for (int i = 0, u, v; i < n - 1; i ++){
55         cin >> u >> v;
56         g[u].push_back(v);
57         g[v].push_back(u);
58     }
59     
60     dfs(1, 0, 1ll << 35, 0, 0ll, 0ll);
61 
62     cout << "YES\n";
63     for (int i = 1; i <= n; i ++)
64         cout << ans[i].st << " " << ans[i].nd << endl;
65 }
code by cj

 

F. Dasha and Photos

Problems:

Analysis:

Posted on 2017-02-01 17:16  Recluse_Team  阅读(192)  评论(0编辑  收藏  举报