A. Dasha and Stairs

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

Analysis:

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

 #define PRON "a"
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL "%lld"
using namespace std;
typedef long long ll; int a, b; int main(){
scanf("%d %d", &a, &b);
if ((!a) && (!b)) { puts("NO"); return ; }
if (abs(a - b) <= )
cout << "YES";
else
cout << "NO";
}

Code by Return

B. Dasha and friends

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

Analysis:

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

 #define PRON "b"
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL "%lld"
using namespace std;
typedef long long ll; const int maxn = + ; int n, l, a[maxn], b[maxn], c[maxn], d[maxn]; bool ok(int x){
for (int i = , j = x; i < n; i ++, j ++){
if (j == n)
j = ;
if (c[i] != d[j])
return false;
} return true;
} bool check(){
for (int i = ; i < n; i ++)
if (c[] == d[i] && ok(i))
return true;
return false;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> l;
for (int i = ; i < n; i ++){
cin >> a[i];
if (i)
c[i] = a[i] - a[i - ];
}
c[] = a[] + l - a[n - ];
for (int i = ; i < n; i ++){
cin >> b[i];
if (i)
d[i] = b[i] - b[i - ];
}
d[] = b[] + l - b[n - ]; if (check())
cout << "YES";
else
cout << "NO";
}

Code by cj

C. Dasha and Password

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

Analysis:

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

 #define PRON "c"
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL "%lld"
#define ed second
#define st first
using namespace std;
typedef long long ll; const int maxn = + ; int n, len;
pair<int, int> dig[maxn], sy[maxn], l[maxn];
string s; int get_ans(){
int ans = inf;
for (int i = ; i < n; i ++)
for (int j = ; j < n; j ++)
for (int k = ; k < n; k ++){
if (sy[i].ed != l[j].ed && l[j].ed != dig[k].ed && dig[k].ed != sy[i].ed){
if (~sy[i].st && ~l[j].st && ~dig[k].st)
ans = min(sy[i].st + l[j].st + dig[k].st, ans);
}
}
return ans;
} inline bool is_dig(char c){
return '' <= c && c <= '';
} inline bool is_sy(char c){
return c == '#' || c == '*' || c == '&';
} inline bool is_l(char c){
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> len;
for (int i = ; i < n; i ++){
cin >> s; s[len] = '\0';
dig[i].st = sy[i].st = l[i].st = -;
dig[i].ed = sy[i].ed = l[i].ed = i;
for (int j = , k = len; j <= k; j ++, k --){
if (l[i].st == - && (is_l(s[j]) || is_l(s[k])))
l[i].st = j;
if (dig[i].st == - && (is_dig(s[j]) || is_dig(s[k])))
dig[i].st = j;
if (sy[i].st == - && (is_sy(s[j]) || is_sy(s[k])))
sy[i].st = j; if (~dig[i].st && ~sy[i].st && ~l[i].st)
break;
}
} sort(l, l + n);
sort(dig, dig + n);
sort(sy, sy + n); cout << get_ans();
}

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:

 #include<cstdio>
#include<cstring>
#include<algorithm>
//#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define INF 2000000000
#define Clear(x, Num) memset(x, Num, sizeof(x))
#define Dig(x) ((x>='0') && (x<='9'))
#define Neg(x) (x=='-')
#define G_c() getchar()
#define Maxn 1000010
typedef long long ll; struct Data
{
int rank, id;
ll l, r;
}c[Maxn];
int n;
ll l, r, a[Maxn], b[Maxn]; inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
inline void read(int &x){ char ch; int N=; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-; while ((ch=G_c()) && (!Dig(ch))); } x=ch-; while ((ch=G_c()) && (Dig(ch))) x=x*+ch-; x*=N; }
//inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; }
inline bool cmp(const Data &a, const Data &b) { return a.rank<b.rank; }
int main()
{
scanf("%d%lld%lld", &n, &l, &r);
for (int i=; i<=n; i++) scanf("%lld", &a[i]);
for (int i=; i<=n; i++) scanf("%d", &c[i].rank), c[i].id=i;
sort(c+, c+n+, cmp);
c[].l=l-a[c[].id]; c[].r=r-a[c[].id];
for (int i=; i<=n; i++)
{
c[i].l=max(l-a[c[i].id], c[i-].l+);
c[i].r=min(r-a[c[i].id], c[i-].r+);
if (c[i].l>c[i].r) { puts("-1"); return ; }
}
b[c[n].id]=c[n].l;
for (int i=n-; i>=; i--)
{
c[i].r=min(c[i].r, b[c[i+].id]);
if (c[i].l>c[i].r) { puts("-1"); return ; }
b[c[i].id]=c[i].l;
}
for (int i=; i<=n; i++) printf("%lld ", b[i]+a[i]); puts("");
}

code by return

E. Dasha and Puzzle

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

Analysis:

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

 #define PRON "e"
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL "%lld"
#define st first
#define nd second
using namespace std;
typedef long long ll; #define mp make_pair const int maxn = + ;
const int ax[] = {-, , , };
const int ay[] = {, , , -}; vector<int> g[maxn];
pair<ll, ll> ans[maxn];
int n; inline void fail(){
printf("NO");
exit();
} void dfs(int u, int pre, ll len, int dir, ll x, ll y){
if (g[u].size() > )
fail(); ans[u] = mp(x, y);
for (int i = , v, now_dir = ; i < g[u].size(); i ++){
v = g[u][i];
if (v == pre)
continue; if (pre != && (dir + ) % == now_dir)
now_dir ++; dfs(v, u, len / , now_dir, x + len * (ll)ax[now_dir], y + len * (ll)ay[now_dir]);
now_dir ++;
}
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n;
for (int i = , u, v; i < n - ; i ++){
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
} dfs(, , 1ll << , , 0ll, 0ll); cout << "YES\n";
for (int i = ; i <= n; i ++)
cout << ans[i].st << " " << ans[i].nd << endl;
}

code by cj

F. Dasha and Photos

Problems:

Analysis:

05-10 22:57