Noip simulation exercises 9
- Easier. One AK.
Exercise program
Description
- The body is the capital of revolution, OIers not because of intense study and in front of the computer all day long at the expense of health
health problems. X small design their own exercise program, but he did not know whether the plan is feasible, in other words
that if poor planning may make his strength overruns, so small x Please help him.
One day 1440 minutes, so small x lists all day 1 to 1440 minutes plan.
X with a physically small integer, said he would exercise according to schedule, at the same time, the small x per minute
physical strength will be automatically increased by one. If the physical end of a minute small x is less than zero, then the poor little x
on worn out ......
Input
- The first line is a space-separated two integers n, m, and each represents an initial planned physical value x of the small
number of items.
A second line starting from the m rows, each row describes an exercise program: name, a start time, the end of
inter-b, physical consumption per minute (separated by spaces), starting from the project indicates the beginning of a minute, the b min
late bell end. Exercise program ascending order according to the start time is given, the two projects will not be time conflict
situations.
Output
- The output includes two lines, if the project is feasible, the first line of output "Accepted", the second line of the output of the day
after the last remaining physical; otherwise the first line of output "Runtime Error", the second line of output in the first few minutes
the bell tired dead.
Sample Input
Basketball 1 10 1
Sample output
Accepted
1140
answer:
- Simulation ... ...
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int n, m;
int a[2005];
int main()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
string t; cin >> t;
int u, v, w;
cin >> u >> v >> w;
for(int j = u; j <= v; j++) a[j] += w;
}
for(int i = 1; i <= 1440; i++)
{
n++, n -= a[i];
if(n <= 0) {cout << "Runtime Error\n" << i; return 0;}
}
cout << "Accepted\n" << n;
return 0;
}
Warcraft
Description
- WoW small x is the ecstasy
he was in control of the death knight ghoul and n (numbered 1 ~ n) to go hunting
death knight has a magic, called "death spiral" that can complement HP to Ghoul
course of the fighting the enemy ghouls will attack, ghoul HP will reduce the
small x want to always know the situation of their own forces, namely the k-value of HP's multi-Ghoul how much HP,
in order to decide how to cast spells
ask someone to help him: )
small x 3 kinds of signals sent to you :( underscore the performance spaces in the input data)
A_i_a represent enemy attacks sent to the i-th Ghoul, and the i-th ghoul lost a point
HP, if it's HP <= 0, then the ghoul died (Undead is dying).
The enemy will not attack a dead ghoul.
C_i_a represents Death Knight released a death spiral to the i-th ghoul, and it adds a point HP.
HP is no upper limit value.
Death Knight Death Coil will not be issued to a dead ghoul
Q_k represent you issue a query to the small x
Input
- The first line, a positive integer n
after n represent integers of n initial Ghoul the HP
value is then a positive integer m
signal lines a little less per m row emitted x
Output
- For each inquiry small x, the output of the k-HP multi-Ghoul how much HP, if Ghoul total
shortfall of k, output -1. The number of each line.
The last line of output a number: After the battle, the number of remaining Ghoul
Sample Input
5
1 2 3
4 5
10
Q 2
A 4 6
C 1 4
Q 2
A 2 1
A 3 3
A 1 3
Q 4
C 2 10
Q 1
Sample output
4
5
-1
11
3
answer:
- Balance bare tree problem. I realize with fhq-treap.
- Each modification approach is to delete a point to point before the amendment, then add the modified points.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define N 30005
using namespace std;
struct T {int l, r, val, dat, size;} t[N * 4];
int n, m, root, x, y, z, tot, now;
int a[N];
int read()
{
int x = 0; char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return x;
}
int New(int val)
{
t[++tot].val = val;
t[tot].dat = rand();
t[tot].size = 1;
return tot;
}
void up(int p) {t[p].size = t[t[p].l].size + t[t[p].r].size + 1;}
void split(int p, int val, int &x, int &y)
{
if(!p) {x = y = 0; return;}
if(t[p].val <= val) x = p, split(t[p].r, val, t[p].r, y);
else y = p, split(t[p].l, val, x, t[p].l);
up(p);
}
int merge(int x, int y)
{
if(!x || !y) return x + y;
if(t[x].dat > t[y].dat)
{
t[x].r = merge(t[x].r, y);
up(x); return x;
}
else
{
t[y].l = merge(x, t[y].l);
up(y); return y;
}
}
void insert(int val)
{
split(root, val - 1, x, y);
root = merge(merge(x, New(val)), y);
}
void erase(int val)
{
split(root, val, x, z);
split(x, val - 1, x, y);
y = merge(t[y].l, t[y].r);
root = merge(merge(x, y), z);
}
int valOfRank(int rank)
{
int p = root;
while(p)
{
if(t[t[p].l].size + 1 == rank) break;
else if(t[t[p].l].size >= rank) p = t[p].l;
else rank -= t[t[p].l].size + 1, p = t[p].r;
}
return t[p].val;
}
int main()
{
cin >> n, now = n;
for(int i = 1; i <= n; i++)
{
a[i] = read();
insert(a[i]);
}
cin >> m;
for(int i = 1; i <= m; i++)
{
char c[3]; scanf("%s", c);
if(c[0] == 'A')
{
int pos = read(), val = read();
erase(a[pos]);
a[pos] -= val;
if(a[pos] <= 0) now--;
else insert(a[pos]);
}
else if(c[0] == 'C')
{
int pos = read(), val = read();
erase(a[pos]);
a[pos] += val;
insert(a[pos]);
}
else if(c[0] == 'Q')
{
int rank = read();
if(now < rank) printf("-1\n");
else printf("%d\n", valOfRank(now - rank + 1));
}
}
cout << now;
return 0;
}
Diablo
Description
- Boring small x in the Diablo I ... playing
the hero of the game with n magic
each divided into several levels of magic, the magic has i-th P [i] levels (excluding 0)
of each per magic levels has an effect value a j of the i stage magic effect is
W [i] [j] magic requires a one liter respective magic
later need magic gold, the i-th magic magic the price of c [i]
and only a small x m gold coins (boy without modifier)
your task is to help small x decide how to buy the book to make magic effect of the value of all the magic and most
large
at the beginning of all magic is 0 effect is 0
Input
- The first row of two space-separated integers nm
The following description n n lines magic
i + 1-i-th row is described in the following format Magic
c [i] p [i] w [i] [1] w [i] [2] ... w [i] [p [i]]
Output
- The first output line of an integer, i.e. the value of the maximum effect.
After row n output your program:
i + 1 th line have an integer V [i] denotes the i-th you decide to learn Magic V [i] stage
if the output of multiple solutions they spend a minimum of a group
if more than Solutions any of a group of output
Sample Input
3 10
1 3 1 2 2
2 3 2 4 6
3 3 2 1 10
Sample output
11
1
0
3
answer:
- Linear dp.
- Set DP (i, j) is processed before the magic i, j with the largest value of the effect obtained gold.
- By one - state of the items (i 1), followed by taking this optimal value takes different forms of articles.
- Relatively easy, mainly export program.
- I thought about using a (i, j) the synchronization time of recording when the operator to dp (i, j), when dp (i, j) obtained, with which the article.
- ok, get.
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 2005
using namespace std;
struct Ans {int id, lev;} ans[N];
struct A {int val, id, lev;} a[N][N];
int n, T;
int cnt[N];
int w[N][N], v[N][N], dp[N][N];
bool cmp(Ans x, Ans y) {return x.id < y.id;}
int main()
{
cin >> n >> T;
for(int i = 1; i <= n; i++)
{
int c; cin >> c;
int p; cin >> p;
cnt[i] = p;
for(int j = 1; j <= p; j++)
cin >> v[i][j], w[i][j] = c * j;
}
for(int i = 1; i <= n; i++)
for(int j = 0; j <= T; j++)
for(int k = 0; k <= cnt[i]; k++)
if(j - w[i][k] >= 0)
if(dp[i - 1][j - w[i][k]] + v[i][k] > dp[i][j])
{
dp[i][j] = dp[i - 1][j - w[i][k]] + v[i][k];
a[i][j].id = i, a[i][j].lev = k;
a[i][j].val = w[i][k];
}
else if(dp[i - 1][j - w[i][k]] + v[i][k] == dp[i][j] && w[i][k] < a[i][j].val)
{
dp[i][j] = dp[i - 1][j - w[i][k]] + v[i][k];
a[i][j].id = i, a[i][j].lev = k;
a[i][j].val = w[i][k];
}
cout << dp[n][T] << endl;
int now = T;
for(int i = n; i >= 1; i--)
{
ans[i].id = a[i][now].id;
ans[i].lev = a[i][now].lev;
now = now - a[i][now].val;
}
sort(ans + 1, ans + 1 + n, cmp);
for(int i = 1; i <= n; i++) cout << ans[i].lev << endl;
return 0;
}