一月流水账

1.4

记一下这个日子

1.10

老大安利的 py

码一下..有时间再来 happy py 叭qwqwqwq

 

1.12

http://codeforces.com/gym/101158

A.Rearranging a Sequence

倒着输出,输出过的跳过

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long LL;
 7 const int maxn = 2e5 + 10;
 8 
 9 int vis[maxn],a[maxn];
10 
11 int main()
12 {
13     int n,m;
14     while(scanf("%d %d",&n,&m) != EOF)
15     {
16         for (int i = 1;i <= m;i++)
17     {
18         scanf("%d",&a[i]);
19     }
20 
21     memset(vis,0,sizeof(vis));
22     for (int i = m;i >= 1;i--)
23     {
24         if (!vis[a[i]]) printf("%d\n",a[i]),vis[a[i]] = 1;
25     }
26 
27     for (int i = 1;i <= n;i++)
28     {
29         if (!vis[i]) printf("%d\n",i);
30     }
31     
32 
33     }
34     return 0;
35 }
View Code

 

B.Quality of Check Digits

C.Distribution Center

将x排序后,可以求出每个传送带的l,r 范围

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long LL;
 7 const int maxn = 2e5 + 10;
 8 
 9 struct node
10 {
11     int x,y,id;
12 }a[maxn];
13 
14 int l[maxn],r[maxn];
15 
16 int cmp(node n1,node n2)
17 {
18     return n1.x < n2.x;
19 }
20 
21 int main()
22 {
23     int n,m;
24     while(scanf("%d %d",&n,&m) != EOF)
25     {
26     for (int i = 1;i <= n;i++) l[i] = i,r[i] = i;
27     for (int i = 1;i <= m;i++)
28     {
29         scanf("%d %d",&a[i].x,&a[i].id);
30     }
31     sort(a+1,a+m+1,cmp);
32 
33     for (int i = 1;i <= m;i++)
34     {
35         int id = a[i].id;
36         l[id] = l[id + 1] = min(l[id], l[id + 1]);
37         r[id] = r[id + 1] = max(r[id], r[id + 1]);
38     }
39 
40     //for (int i = 1;i <= n;i++) printf("l[%d] = %d r[%d] = %d\n",i,l[i],i,r[i]);
41 
42     for (int i = 1;i < n;i++) printf("%d ",r[i] - l[i] + 1);
43     printf("%d\n",r[n] - l[n] + 1);
44 
45     }
46     return 0;
47 }
View Code

 

D.Hidden Anagrams

E.Infallibly Crack Perplexing Cryptarithm

F.Three Kingdoms of Bourdelot

隔一个分别加

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 int a[105],n;
 8 
 9 int main()
10 {
11     scanf("%d",&n);
12     for (int i = 1;i <= n;i++) scanf("%d",&a[i]);
13     sort(a+1,a+n+1);
14     int l = 0,r = 0,flag = 0;
15     for (int i = n;i >= 1;i--)
16     {
17         if (flag == 0) l += a[i];
18         else r += a[i];
19         flag = !flag;
20     }
21 
22     printf("%d %d\n",l,r);
23 
24     return 0;
25 }
View Code

 

G.Placing Medals on a Binary Tree

一看题目马上想到15上海那个二叉树的构造,但好像没什么关系qaq

当加入一个x的时候,首先考虑还能不能放,先看0 有没有被占,如果0被占了,怎么都放不了;再维护一个pos,表示到pos这个高度都没法再放,每次遇到不能放的,更新pos

再用一个map存到这个高度是否被放过了

能放,用 x 再去合并,两个 x 相当于一个 x - 1

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <map>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 bool ok(int x,map<int,int>& h,int& pos)
 9 {
10     if (x <= pos) return false;
11     map<int,int>::iterator it = h.upper_bound(x);
12     int cpx = x;
13     if (it != h.end())
14     {
15         while(x != 0)
16         {
17             if (x <= pos || h[x] == 0) break;
18             x -= 1;
19         }
20         if (x <= pos) {pos = max(pos,cpx);return false;}
21         if (x == 0) pos = max(pos,cpx);
22         return x != 0;
23     }
24     else return true;
25 }
26 
27 int main()
28 {
29     map<int,int> h;
30     int n,x,pos = -1;
31     scanf("%d",&n);
32     for (int i = 1;i <= n;i++)
33     {
34         scanf("%d",&x);
35         if (h[0])
36         {
37             puts("No");
38             continue;
39         }
40         if (ok(x,h,pos))
41         {
42             puts("Yes");
43             while(h[x] != 0)
44             {
45                 h.erase(x);x--;
46             }
47             h[x] = 1;
48         }
49         else puts("No");
50     }
51     return 0;
52 }
View Code

 

H.Animal Companion in Maze

I.Skinny Polygon

J.Cover the Polygon with Your Disk

K.Black and White Boxes

 

 

1.17

http://codeforces.com/gym/101666

题解

A.Amsterdam Distance

B.Bearly Made It

C.Collatz Conjecture

D.Detour

E.Easter Eggs

F.Falling Apart

G.Going Dutch

H.Hoarse Horses

I.Irrational Division

J.Jumping Choreography

很神奇!

可以先打表(可是打表也没看出规律...

距离x 需要的步数约等于 sqrt(2 * x) ,所以对于 1e6 的距离,最多需要sqrt(2 * 1e6) = 1500,所以可以用树状数组存 每一个 距离的答案,每一次放青蛙,就是update 1500个区间

然后对于青蛙跳的距离和步数,观察可以得到,分奇偶,是单调递增的,具体的,可以看个例子

距离 -5 -4 -3 -2 -1 0 1 2 3 4 5

步数 5   3  2  3  1  0 1  3 2 3 5

对于[4,15]的所有奇数 都最少需要跳15步,对于[4,6]的偶数都最少需要跳3步,(就是前 1 + 2 +... + n 第一次为偶(奇)和上一次为偶(奇)构成的区间)

然后,可以用到树状数组,区间更新,单点查询(前缀和的感觉,这个

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <map>
 7 using namespace std;
 8 const int maxn = 1e6 + 5;
 9 int n,t,even[maxn],odd[maxn];
10 
11 int lowbit(int x) {return x & (-x);}
12 
13 void add(int i,int x,int* c)
14 {
15     while(i < maxn) {c[i] += x;i += lowbit(i);}
16 }
17 
18 int query(int i,int* c)
19 {
20     int ret = 0;
21     while(i > 0) {ret += c[i]; i -= lowbit(i);}
22     return ret;
23 }
24 
25 void update(int l,int r,int x,int* c)
26 {
27     l = max(1,l);
28     if (l <= r)
29     {
30         add(l,x,c);
31         add(r+1,-x,c);
32     }
33 }
34 
35 void update(int p,int v)
36 {
37     int l = p,r = p,evenl = p,evenr = p,oddl = p,oddr = p,step = 1;
38     while(evenl >= 1 || evenr < maxn || oddl >= 1 || oddr < maxn)
39     {
40         l -= step;r += step;
41         if (r & 1)
42         {
43             update(l,evenl - 1,v * step,odd);
44             update(evenr + 1,r,v * step,odd);
45             evenl = l;evenr = r;
46             // printf("l = %d r = %d [%d %d]  [%d %d] \n",l,r,l,evenl-1,evenr+1,r);
47         }
48         else
49         {
50             update(l,oddl - 1,v * step,even);
51             update(oddr + 1,r,v * step,even);
52             oddl = l;oddr = r;
53         }
54         step++;
55     }
56 }
57 
58 int main()
59 {
60     scanf("%d %d",&n,&t);
61     int x;
62     for (int i = 1;i <= n;i++)
63     {
64         scanf("%d",&x);
65         update(x+1,1);
66     }
67 
68     int q,pos = t;
69     string cmd;
70     scanf("%d",&q);
71     for (int i = 1;i <= q;i++)
72     {
73         cin >> cmd >> x;
74         if (cmd == "t") pos = x;
75         else
76         {
77             if (cmd == "+") update(x + 1,1);
78             else update(x + 1,-1);
79         }
80         printf("%d\n",pos & 1 ? query(pos+1,even):query(pos+1,odd));
81     }
82     return 0;
83 }
84 
85 
86 /*
87 
88 5 6
89 1 2 3 4 5
90 
91 */
View Code

 

K.King of the Waves

L.Lemonade Trade

M.Manhattan Mornings

先找出在矩形区域里的点,按照x排序后,求y的不严格上升子序列

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 const int maxn = 1e5 + 5;
 8 int n;
 9 int sx,sy,ex,ey;
10 
11 struct point
12 {
13     int x,y;
14 }p[maxn];
15 
16 point cp[maxn];
17 int c[maxn];
18 
19 bool cmp(point n1,point n2)
20 {
21     if (n1.x != n2.x) return n1.x < n2.x;
22     return n1.y < n2.y;
23 }
24 
25 int main()
26 {
27     scanf("%d",&n);
28     scanf("%d %d %d %d",&sx,&sy,&ex,&ey);
29     for (int i = 1;i <= n;i++) scanf("%d %d",&p[i].x,&p[i].y);
30     int mnx = min(sx,ex),mny = min(sy,ey);
31     int mx = max(sx,ex),my = max(sy,ey);
32 
33     int tot = 0;
34     for (int i = 1;i <= n;i++)
35     {
36         if (p[i].x >= mnx && p[i].y >= mny && p[i].x <= mx && p[i].y <= my) cp[++tot] = p[i];
37     }
38 
39     if (ey < sy)
40     {
41         for (int i = 1;i <= tot;i++) cp[i].y = -1 * cp[i].y;
42     }
43     if (ex < sx)
44     {
45         for (int i = 1;i <= tot;i++) cp[i].x = -1 * cp[i].x;
46     }
47     sort(cp+1,cp+tot+1,cmp);
48 
49     int len = 0;
50     if (tot != 0)
51     {
52         c[++len] = cp[1].y;
53         for (int i = 2;i <= tot;i++)
54         {
55             if (cp[i].y >= c[len])
56             {
57                 c[++len] = cp[i].y;
58             }
59             else
60             {
61                 int pos = upper_bound(c + 1,c + len + 1,cp[i].y) - c;
62                 c[pos] = cp[i].y;
63             }
64         }
65 
66     }
67 
68     printf("%d\n",min(len,n));
69 
70     return 0;
71 }
72 
73 
74 /*
75 
76 3
77 0 0 6 6
78 5 4
79 2 6
80 3 1
81 
82 5
83 2 1 0 0
84 0 0
85 0 1
86 2 0
87 2 1
88 3 1
89 
90 4
91 200 100 100 200
92 50 150
93 200 200
94 100 100
95 100 100
96 
97 */
View Code

 

---------------------

虽然知道这个结果毫不意外... 但是也是警醒.....要努力呀!

加油!

 

1.19

http://codeforces.com/gym/101630

A.Archery Tournament

B.Box

C.Connections

D.Designing the Toy

E.Easy Quest

F.The Final Level

G.The Great Wall

H.Hack

I.Interactive Sort

J.Journey from Petersburg to Moscow

K.Knapsack Cryptosystem

L.Laminar Family

 

1.21

http://codeforces.com/gym/101611

A.Advertising Strategy

B.Byteland Trip

C.Carpet

D.Decoding of Varints

E.Empire History

F.Fake or Leak?

wa了很久的模拟,暴露出来的问题蛮多的

读题不仔细,需要判断的k个已经保证是合法的,不需要再判断了

存的东西很多,读入最好写成一个函数,变量顺序放错有可能就导致没有赋上值

考虑还是不够周到,在update之前需要先判断,因为有可能是更好的被Update成不那么好了(update 就是假设其在封榜之前AK)

真的qaqaqaqaqaqaaaa了

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <iostream>
  4 #include <map>
  5 #include <vector>
  6 #include <algorithm>
  7 using namespace std;
  8 const int maxn = 1005;
  9 
 10 struct node
 11 {
 12     string name;
 13     int id,solved,time,last;
 14     // 记录每一次提交 第几题 wa的次数 最后一次提交的时间
 15     vector<pair<string,pair<int,int> > > vec;
 16 }a[maxn];
 17 
 18 node b[maxn];
 19 
 20 map<string,int> h;
 21 map<int,string> rh;
 22 int n,m,k,vis[maxn];
 23 
 24 void print(int id)
 25 {
 26     printf("id = %d name = %s solved = %d time = %d last = %d\n",id,a[id].name.c_str(),a[id].solved,a[id].time,a[id].last);
 27     printf("\n");
 28 }
 29 
 30 int cal(int l,int mid)
 31 {
 32     //print(l);print(mid);
 33     if (a[mid].solved != a[l].solved) return a[l].solved > a[mid].solved;
 34     if (a[mid].time != a[l].time) return a[l].time < a[mid].time;
 35     if (a[mid].last != a[l].last) return a[l].last < a[mid].last;
 36     return a[l].name < a[mid].name;
 37 }
 38 
 39 void update(int id)
 40 {
 41     if (a[id].solved == n) return;
 42     a[id].solved = n;
 43     a[id].last = 240;
 44     int time = 0;
 45     for(int i = 0;i < a[id].vec.size();i++)
 46     {
 47         pair<string,pair<int,int> > u = a[id].vec[i];
 48         if (u.first == "+") continue;
 49         time += (u.second.first * 20 + 240);
 50     }
 51     a[id].time += time;
 52 }
 53 
 54 node read(int id)
 55 {
 56     node u;
 57     string name,cmd;
 58     int x,y;
 59     cin >> u.name;
 60     int tot = 0,last = 0,cnt = 0;
 61     for (int i = 1;i <= n;i++)
 62     {
 63         cin >> cmd >> x >> y;
 64         pair<string,pair<int,int> > v = make_pair(cmd,make_pair(x,y));
 65         u.vec.push_back(v);
 66 
 67         if (cmd == "+")
 68         {
 69             cnt++;
 70             tot = tot + (x - 1) * 20 + y;
 71             last = max(last,y);
 72         }
 73     }
 74     u.solved = cnt;
 75     u.id = id;
 76     u.time = tot;
 77     u.last = last;
 78     return u;
 79 }
 80 
 81 void solve()
 82 {
 83     int st = h[b[1].name],ed = h[b[k].name];
 84     for (int i = 1;i <= m;i++)
 85     {
 86         if (vis[i]) continue;
 87         if (cal(i,st) || cal(ed,i)) continue;
 88         update(i);
 89         if (cal(i,st) || cal(ed,i)) continue;
 90         puts("Fake");
 91         return;
 92     }
 93     puts("Leaked");
 94 }
 95 
 96 int main()
 97 {
 98     scanf("%d %d %d",&n,&m,&k);
 99     int tot = 0;
100     for (int i = 1;i <= m;i++)
101     {
102         a[i] = read(i);
103         h[a[i].name] = i;rh[i] = a[i].name;
104     }
105     memset(vis,0,sizeof(vis));
106     for (int i = 1;i <= k;i++)
107     {
108         b[i] = read(i);
109         vis[h[b[i].name]] = 1;
110         a[h[b[i].name]] = b[i];
111     }
112 
113     solve();
114 
115     return 0;
116 }
117 
118 
119 /*
120 
121 3 3 2
122 crabs + 1 1 + 1 2 + 1 3
123 lions . 0 0 - 5 239 . 0 0
124 wombats . 0 0 . 0 0 . 0 0
125 
126 
127 wombats + 1 241 + 3 299 - 22 299
128 lions + 1 241 + 6 240 - 3 299
129 
130 Leaked
131 
132 
133 3 4 1
134 crabs + 1 1 + 1 2 + 1 3
135 lions . 0 0 + 5 239 . 0 0
136 wolves . 0 0 . 0 0 . 0 0
137 wombats . 0 0 . 0 0 . 0 0
138 crabs + 1 1 + 1 2 + 1 3
139 
140 
141 
142 Fake
143 
144 
145 
146 */
View Code

赛时写的代码也改过来了...非常让人难受的错,都是一些很小很小的细节,last 初始化不对,时间居然 写成 = ,而没有累加.... 以后一定要更加仔细阿

记一下这个教训叭 

// 不管 做什么 ..... 其实都是很马虎.... 只是很多事情没有放到像acm 这样 这么严苛的环境下去考量叭 .... 加油加油 慢慢改叭

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <iostream>
  4 #include <map>
  5 #include <vector>
  6 #include <algorithm>
  7 using namespace std;
  8 const int maxn = 1005;
  9 
 10 struct node
 11 {
 12     string name;
 13     int id,solved,time,last;
 14     // 第几题 wa的次数 最后一次提交的时间
 15     map<int,pair<int,int> > wa;
 16 }a[maxn];
 17 
 18 node b[maxn];
 19 
 20 map<string,int> h;
 21 map<int,string> rh;
 22 int n,m,k,vis[maxn];
 23 
 24 int cal(int l,int mid)
 25 {
 26     if (a[mid].solved != a[l].solved) return a[l].solved > a[mid].solved;
 27     if (a[mid].time != a[l].time) return a[l].time < a[mid].time;
 28     if (a[mid].last != a[l].last) return a[l].last < a[mid].last;
 29     return a[l].name < a[mid].name;
 30 }
 31 
 32 void update(int id)
 33 {
 34     if (a[id].solved == n) return;
 35     a[id].solved = n;
 36     a[id].last = 240;
 37     int time = 0;
 38     for(map<int,pair<int,int> >::iterator it = a[id].wa.begin();it != a[id].wa.end();it++)
 39     {
 40         pair<int,int> u = it->second;
 41         time += (u.first * 20 + 240);
 42     }
 43     a[id].time += time;
 44     
 45 }
 46 
 47 int main()
 48 {
 49     scanf("%d %d %d",&n,&m,&k);
 50     int tot = 0;
 51     for (int i = 1;i <= m;i++)
 52     {
 53         string name;
 54         cin >> name;
 55         h[name] = i;
 56         int cnt = 0,tmp = 0,_last = 0;
 57         string cmd;
 58         int x,y;
 59         for (int j = 1;j <= n;j++)
 60         {
 61             cin >> cmd >> x >> y;
 62             if (cmd == "+")
 63             {
 64                 cnt++;
 65                 tmp += (x - 1) * 20 + y;
 66                 _last = max(_last,y);
 67             }
 68             if (cmd == "-" || cmd == ".")
 69             {
 70                 a[i].wa[j] = make_pair(x,y);
 71             }
 72         }
 73         a[i].name = name;
 74         a[i].id = i;
 75         a[i].solved = cnt;
 76         a[i].time = tmp;
 77         a[i].last = _last;
 78     }
 79 
 80     memset(vis,0,sizeof(vis));
 81     int flag = 1;
 82     for (int i = 1;i <= k;i++)
 83     {
 84         string name;
 85         cin >> name;
 86         string cmd;
 87         int x,y,_last = 0;
 88         node u;
 89         int cnt = 0,tmp = 0;
 90         for (int j = 1;j <= n;j++)
 91         {
 92             cin >> cmd >> x >> y;
 93             if (cmd == "+")
 94             {
 95                 cnt++;
 96                 tmp += (x - 1) * 20 + y;
 97                 _last = max(_last,y);
 98             }
 99             if (cmd == "-" || cmd == ".")
100             {
101                 u.wa[j] = make_pair(x,y);
102             }
103         }
104         u.name = name;
105         u.id = h[name];
106         u.solved = cnt;
107         u.time = tmp;
108         b[i] = u;
109         vis[u.id] = 1;
110         u.last = _last;
111         a[u.id] = u;
112     }
113 
114     for (int i = 1;i <= m;i++)
115     {
116         if (vis[i]) continue;
117         if (cal(b[k].id,i) ) continue;
118         update(i);
119         if (cal(i,b[1].id)) continue;
120         flag = 0;
121     }
122 
123     if (flag == 1) puts("Leaked");
124     else puts("Fake");
125 
126     return 0;
127 }
128 
129 
130 /*
131 
132 3 3 2
133 crabs + 1 1 + 1 2 + 1 3
134 lions . 0 0 - 5 239 . 0 0
135 wombats . 0 0 . 0 0 . 0 0
136 
137 
138 wombats + 1 241 + 3 299 - 22 299
139 lions + 1 241 + 6 240 - 3 299
140 
141 Leaked
142 
143 
144 3 4 2
145 crabs + 1 1 + 1 2 + 1 3
146 lions . 0 0 + 5 239 . 0 0
147 wolves . 0 0 . 0 0 . 0 0
148 wombats . 0 0 . 0 0 . 0 0
149 crabs + 1 1 + 1 2 + 1 3
150 wombats . 0 0 + 2 299 . 0 0
151 
152 
153 Fake
154 
155 
156 
157 */
View Code

 

 

 

G.God of Winds

H.Hilarious Cooking

I.Infinite Gift

J.Judging the Trick

试图随机水水样例,可是连第一个都过不去qaqaqaq

 

转载于:https://www.cnblogs.com/wuyuewoniu/p/8204528.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值