DUT Star Round2

A.Zeratu的军训游戏

Problems: 开灯问题,问无数次操作之后第n盏灯的状态

Analysis:

  cj:平方数有奇数个约数

Tags: Implementation

B.Zeratud的完美区间

Problems: 对于一个[1, n]的排列中,询问区间[l, r]中数字是否连续

Analysis:

  cj:智障的我想了一个及其错误的算法,后来被lucky_ji点醒,if (区间最大值最小值之差 == 区间长度)就好了。。

Tags: Data Structure, Dynamic Programming

C. ACM群日常禁言一万年

Problems: 秒数转换为xdays, hh/mm/ss

Tags: Implementation

D.Zeratud与LCM

Problems: 构造长度为n的序列{a},使得LCM(a1, a2, ......, an) = a1 + a2 + ...... + an

Analysis:

Tags: Math

E.小q与面试题

Problems: 维护一个可以查询最小值的栈

Analysis:

  cj: 这种题最适合用STL乱搞了

Tags: Data Structure

 1 #define PRON "e"
 2 #include <set>
 3 #include <stack>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 #define inf 0x3f3f3f3f
 9 using namespace std;
10 typedef long long ll;
11
12 const int maxn = 500000 + 10;
13
14 stack<int> q;
15 multiset<int> s;
16
17 char ch;
18 inline void read(int & x){
19     int flag = 1;
20     do {
21         if (ch == ‘-‘)
22             flag = -1;
23         ch = getchar();
24     } while (!(‘0‘ <= ch && ch <= ‘9‘));
25
26     x = 0;
27     do {
28         x = x * 10 + ch - ‘0‘;
29         ch = getchar();
30     } while (‘0‘ <= ch && ch <= ‘9‘);
31
32     x *= flag;
33 }
34
35 int main(){
36 #ifndef ONLINE_JUDGE
37     freopen(PRON ".in", "r", stdin);
38 #endif
39     s.clear();
40     while (not q.empty())
41         q.pop();
42
43
44     int T, a, b, sum = 0;
45     read(T);
46     while (T --){
47         read(a);
48         if (a == 0){
49             read(b);
50             ++ sum;
51             s.insert(b);
52             q.push(b);
53         }
54         if (a == 1){
55             if (sum == 0)
56                 puts("ERROR!");
57             else
58                 printf("%d\n", q.top());
59         }
60         if (a == 2){
61             if (sum == 0)
62                 puts("ERROR!");
63             else
64                 printf("%d\n", *s.begin());
65         }
66         if (a == 3){
67             if (sum == 0)
68                 puts("ERROR!");
69             else {
70                 -- sum;
71                 s.erase(s.find(q.top()));
72                 q.pop();
73             }
74         }
75     }
76 }
77
78     

Code by cj

F.Zeratu与QQ堂

Problems: 放置m次炸弹(不能在转快上放置),每次炸掉上下左右最近的砖块,输出最后剩余的砖块

Analysis:

  cj: 直接模拟会Time Limit Exceeded,用row[i]存储第i行的砖块的j坐标,col[j]存储第j行砖块的i坐标。每一次放置炸弹成功后,二分找到前后和左右的砖块并且erase

Tags: Implementation

  1 #define PRON "f"
  2 #include <vector>
  3 #include <cstdio>
  4 #include <cstring>
  5 #include <iostream>
  6 #include <algorithm>
  7 using namespace std;
  8 typedef long long ll;
  9
 10 #define lb lower_bound
 11 #define r(y, x) lb(row[y].begin(), row[y].end(), x)
 12 #define c(x, y)    lb(col[x].begin(), col[x].end(), y)
 13
 14 const int maxn = 1000 + 10;
 15
 16 int n, sum = 0;
 17 char s[maxn][maxn];
 18 vector<int> row[maxn], col[maxn];
 19
 20 int main(){
 21 #ifndef ONLINE_JUDGE
 22     freopen(PRON ".in", "r", stdin);
 23 #endif
 24
 25     scanf("%d", &n);
 26     for (int i = 0; i < n; i ++){
 27         scanf("%s", s[i]);
 28
 29         for (int j = 0; j < n; j ++)
 30             if (s[i][j] == ‘*‘)
 31                 ++ sum;
 32     }
 33
 34     for (int i = 0; i < n; i ++)
 35         for (int j = 0; j < n; j ++)
 36             if (s[i][j] == ‘*‘)
 37                 row[i].push_back(j);
 38
 39     for (int j = 0; j < n; j ++)
 40         for (int i = 0; i < n; i ++)
 41             if (s[i][j] == ‘*‘)
 42                 col[j].push_back(i);
 43
 44     int q, x, y, pos;
 45     scanf("%d", &q);
 46     while (q --){
 47         scanf("%d %d", &y, &x);
 48
 49         if ((not row[y].empty() && *(r(y, x)) == x) && (not col[x].empty() && *(c(x, y)) == y))
 50             continue;
 51
 52         if (not row[y].empty()){
 53             -- sum;
 54             if (x < *row[y].begin()){
 55                 col[*row[y].begin()].erase(c(*row[y].begin(), y));
 56                 row[y].erase(row[y].begin());
 57             }
 58             else if (x > *(row[y].end() - 1)){
 59                 col[*(row[y].end() - 1)].erase(c(*(row[y].end() - 1), y));
 60                 row[y].erase(row[y].end() - 1);
 61             }
 62             else {
 63                 -- sum;
 64                 pos = r(y, x) - row[y].begin();
 65                 col[row[y][pos]].erase(c(row[y][pos], y));
 66                 col[row[y][pos - 1]].erase(c(row[y][pos - 1], y));
 67
 68                 row[y].erase(pos + row[y].begin());
 69                 row[y].erase(pos - 1 + row[y].begin());
 70             }
 71         }
 72
 73         if (not col[x].empty()){
 74             -- sum;
 75             if (y < *col[x].begin()){
 76                 row[*col[x].begin()].erase(r(*col[x].begin(), x));
 77                 col[x].erase(col[x].begin());
 78             }
 79             else if (y > *(col[x].end() - 1)){
 80                 row[*(col[x].end() - 1)].erase(r(*(col[x].end() - 1), x));
 81                 col[x].erase(col[x].end() - 1);
 82             }
 83             else {
 84                 -- sum;
 85                 pos = c(x, y) - col[x].begin();
 86                 row[col[x][pos]].erase(r(col[x][pos], x));
 87                 row[col[x][pos - 1]].erase(r(col[x][pos - 1], x));
 88
 89                 col[x].erase(pos + col[x].begin());
 90                 col[x].erase(pos - 1 + col[x].begin());
 91             }
 92         }
 93
 94     }
 95
 96
 97     printf("%d\n", sum);
 98 }
 99
100     

Code by cj

G.Zeratu的最优路径

Problems: 数字“正方形”

Tags: Dynamic Programming

时间: 2024-08-13 15:53:33

DUT Star Round2的相关文章

poj-2420 A Star not a Tree?(模拟退火算法)

题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepted: 2491 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allo

在简历中使用STAR法则

一.什么是STAR法则? The STAR (Situation, Task, Action, Result) format is a job interview technique used by interviewers to gather all the relevant information about a specific capability that the job requires. This interview format is said to have a higher

MB Star C3 DAS Fault (1.1)-1.501.9504 (Solved)

I have had a Mercedes diagnostic machine MB STAR C3 for a while and i decided to try and make it work, but every time i try to communicate with the car i get  an error message saying : Fault (1.1)-1.501.9504Initialization of diagnosis multiplexer fai

WordPress 一键置顶文章(推荐用SM Sticky Clicky Star)

在 WordPress入门 之 发布新文章和管理文章 中,倡萌已经简单提到可以在文章编辑界面或者快速编辑界面设置置顶文章,但是如果你想在后台文章列表中添加一键置顶文章的功能,不妨试试 Quick Sticky 或 SM Sticky Clicky Star 插件. Quick Sticky 和 SM Sticky Clicky Star 都是用来给后台文章列表添加一键置顶文章功能的,一个较大的不同是,SM Sticky Clicky Star 支持 Ajax 无刷新设置,而 Quick Stic

Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c). Over time the stars twinkle. At moment 0 the i-th

字付串函数 substring(ex,star,end)

1 --substring(ex,star,end) 2 SELECT SUBSTRING(Name, 1, 2) AS ProductName, ListPrice 3 FROM Production.Product order by ProductName 4 5 SELECT Name FROM Production.Product order by Name 6 7 select * from Production.Product 8 9 10 SELECT SUBSTRING(Name

POJ 2420 A Star not a Tree? (计算几何-费马点)

A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 1724 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you

[POJ 2420] A Star not a Tree?

A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 2005 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you

HDU 1541 star (树状数组)

Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5400    Accepted Submission(s): 2133 Problem Description Astronomers often examine star maps where stars are represented by points on a plan