NOIP 2017 模拟
11 3
T1:
题目:
难以置信这竟然会是T1。天呐,我到底参加的是NOI in Provinces还是NOI Plus 啊啊啊。。
——正解思路:
——我的乱搞:
暴力匹配,n * n * m大暴力。。。
——tips:
编程不止眼前的暴力,还有远方的暴力。
写暴力之前心中一定要有B数。。。
满载悲伤的代码:
(诶我操,正解代码怎么T了?????)
(代码掺了金(#pragma)坷(GCC)垃(optimize("O3)),一秒能当两秒花)
#pragma GCC optimize("O3")
#include
#include
T2:
题目:
——正解思路:
——我的乱搞:
天呐,这不是个 vector + erase 风骚走位水题嚒??关键是还真TM AK了???!!!
写线段树的大佬们一脸蒙逼。。。。。。。。。。
——tips :
那么这就很监介了,,真 - 暴力出奇迹。
#pragma GCC optimize("O3")
#include
#include
int n;
int p[100010];
std::vector v;
inline void read (int &x) {
x = 0;
register char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
}
inline void write (int x) {
short num = 0;
char c[10];
while (x) c[++num] = x % 10 | 48, x /= 10;
while (num) putchar(c[num--]);
putchar(' ');
}
int main () {
read (n);
for (register int i = 1; i <= n; ++i) read (p[i]), v.push_back(i);
std::vector :: iterator it;
for (register int i = n; i >= 1; --i) {
it = v.begin() + i - p[i] - 1 + p[i - 1];
p[i] = *it;
v.erase(it);
}
for (register int i = 1; i <= n; ++i) write (p[i]);
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int n,pre,now,tmp,l,r,mid;
int a[100010],tree[100010];
void read(int &x)
{
x=0;
char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch))
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
}
int lowbit(int x)
{
return x&(-x);
}
int get(int x)
{
int ans=0;
while(x>=1)
{
ans+=tree[x];
x-=lowbit(x);
}
return ans;
}
void add(int x,int y)
{
while(x<=n)
{
tree[x]+=y;
x+=lowbit(x);
}
}
int main()
{
//freopen("premu.in","r",stdin);
read(n);
pre=0;
for(int i=1;i<=n;++i)
{
read(now);
a[i]=now-pre;
pre=now;
}
for(int i=1;i<=n;++i) add(i,1);
for(int i=n;i>=1;i--)
{
tmp=i-a[i];
l=0,r=n;
while(l+1>1;
if(get(mid)
T3 :
题目:
点击回复你也查看不了
在USACO上学的暴力技巧派上用场了耶。。。。。
——正解思路:
——我的乱搞:
暴搜 + vector 剪枝。
——tips:
good good 暴力, day day 爆零。
满载一种难以言表的思想感情的代码:
#include
#include
#include
#define MIN(a, b) a = min(a, b)
#define SOLVE(a, b) \
for (register int x = 1; x <= n; ++x) for (register int y = 1; y <= n; ++y) a[i][x][y] = a[i + b][x][y] + road[i].r;\
for (register int x = 1; x <= n; ++x) {\
if (a[i + b][x][road[i].y] < inf) MIN(a[i][x][road[i].x], a[i + b][x][road[i].y] + road[i].c);\
if (a[i + b][x][road[i].x] < inf) MIN(a[i][x][road[i].y], a[i + b][x][road[i].x] + road[i].c);}
using namespace std;
struct node{
int x, y, c, r;
}road[30001];
struct query{
int x, y, l, r, id;
}qry[300001], tag[300001];
int n, m, q;
int ans[300001];
int Left[30001][31][31], Right[30001][31][31];
const int inf = 1e+9;
inline int read () {
register int x = 0;
register char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
return x;
}
inline void write (int x) {
char num = 0, c[10];
if (x < 0) putchar('-'), x = -x;
do c[++num] = x % 10 | 48, x /= 10; while (x);
while (num) putchar(c[num--]);
putchar('\n');
}
inline void solve(int lr, int rr, int lq, int rq) {
if (lq > rq) return;
if (lr == rr) {
for (register int i = lq; i <= rq; ++i)
if (qry[i].x != qry[i].y) {
ans[qry[i].id] = (qry[i].x == road[lr].x and qry[i].y == road[lr].y) ? road[lr].c : -1;
} else {
ans[qry[i].id] = inf;
(qry[i].x == road[lr].x and qry[i].y == road[lr].y) ? ans[qry[i].id] = road[lr].c : 0;
MIN(ans[qry[i].id], road[lr].r);
}
return;
}
int mid = lr + rr >> 1;
for (register int i = 1; i <= n; ++i)
for (register int j = 1; j <= n; ++j)
Left[mid + 1][i][j] = Right[mid][i][j] = inf;
for (register int i = 1; i <= n; ++i)
Left[mid + 1][i][i] = Right[mid][i][i] = 0;
for (register int i = mid; i >= lr; --i) {SOLVE(Left, 1)}
for (register int i = mid + 1; i <= rr; ++i) {SOLVE(Right, -1)}
for (register int i = lq; i <= rq; ++i) if (qry[i].l <= mid and qry[i].r > mid) {
int value = inf;
for (register int x = 1; x <= n; ++x) MIN(value, Left[qry[i].l][x][qry[i].x] + Right[qry[i].r][x][qry[i].y]);
ans[qry[i].id] = value < inf ? value : -1;
}
for (register int i = lq; i <= rq; ++i) tag[i] = qry[i];
int wl = lq - 1, wr = rq + 1;
for (register int i = lq; i <= rq; ++i) {
if (tag[i].r <= mid) qry[++wl] = tag[i];
if (tag[i].l > mid) qry[--wr] = tag[i];
}
solve(lr, mid, lq, wl);
solve(mid + 1, rr, wr, rq);
}
int main () {
n = read(), m = read(), q = read();
for (register int i = 1; i <= m; ++i) road[i] = (node){read(), read(), read(), read()};
for (register int i = 1; i <= q; ++i) qry[i] = (query){read(), read(), read(), read(), i};
solve(1, m, 1, q);
for (register int i = 1; i <= q; ++i) write(ans[i]);
return 0;
}