2013 只有一次,也放这了。

201312

201403

1. 相反数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f;

int n, ans;
int vis[1005];

int main() 
{
    scanf("%d", &n);
    int x;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &x);
        x = abs(x);
        if (!vis[x]) vis[x] = 1;
        else ans++;
    }
    printf("%d\n", ans);
    return 0;
}

2. 窗口

  用 vector 存窗口,每次从最顶层遍历,找到包含 (x,y) 的窗口移到最顶层,用注释掉的部分只有 90 分。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;

#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f;

struct window {
    int ax, ay, bx, by;
    int id;
    window() {}
    window(int ax, int ay, int bx, int by, int id) : ax(ax), ay(ay), bx(bx), by(by), id(id) {}
};

int n, m;
vector<window> windows;

void click(int x, int y) {
    /*for (vector<window>::reverse_iterator it = windows.rbegin(); it != windows.rend(); ++it) {
        if (x >= it->ax && x <= it->bx)
            if (y >= it->ay && y <= it->by) {
                printf("%d\n", it->id);
                windows.push_back(*it);
                windows.erase((++it).base());
                return;
            }
    }*/
    for (int i = windows.size() - 1; i >= 0; --i) {
        if (x >= windows[i].ax && x <= windows[i].bx)
            if (y >= windows[i].ay && y <= windows[i].by) {
                printf("%d\n", windows[i].id);
                windows.push_back(windows[i]);
                windows.erase(windows.begin() + i);
                return;
            }
    }
    puts("IGNORED");
}

int main() 
{
    int ax, ay, bx, by;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d%d%d", &ax, &ay, &bx, &by);
        windows.push_back(window(ax, ay, bx, by, i));
    }
    int x, y;
    while (m--) {
        scanf("%d%d", &x, &y);
        click(x, y);
    }
    return 0;
}

3. 命令行选项

  算是道 csp 认证第三题中简单的模拟题。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <sstream>
using namespace std;

#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f;

int n;
string format, str, s, para;
map<char, int> patt;
map<string, string> ans;

int main() 
{
    cin >> format;
    int len = format.length();
    for (int i = 0; i < len; ++i) {
        if (format[i] == ':') patt[format[i-1]] = 2;
        else patt[format[i]] = 1;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        cin >> str;
        getline(cin, str);
        stringstream ss(str);
        while (ss >> s) {
            if (s.length() == 2 && s[0] == '-' && isalpha(s[1])) {
                if (patt[s[1]] == 1) ans[s] = "NO";
                else if (patt[s[1]] == 2) { ss >> para; ans[s] = para; }
                else break;
            }
            else break;
        }
        printf("Case %d: ", i);
        for (map<string, string>::iterator it = ans.begin(); it != ans.end(); ++it) {
            if (it->second != "NO") { cout << it->first << ' ' << it->second << ' '; }
            else cout << it->first << ' ';
        }
        puts("");
        ans.clear();
    }
    return 0;
}