我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,把官方给出的题解贴出来!

                                    A -- Niro plays Galaxy Note 7                   

Time Limit:1s

Memory Limit:128MByte

DESCRIPTION

Niro, a lovely girl, has bought a Galaxy Note 7 and wants to destroy cities. There are N cities numbered 1... N on a line and each pair of adjacent cities has distance 1. Galaxy Note 7 has its explosion radius R. Niro puts her Galaxy Note 7 in city X and city i will be destroyed if (|X−i|≤R)

.You must tell Niro how many cities wil be destroyed.

   

INPUT

The first line contains a positive integer T, the number of test cases.
Each of the following T lines contains three integers N, R, X
.

OUTPUT

Tlines.Each line contains one integer, the answer.
      

SAMPLE INPUT

3
100 5 23
100 8 36
100 9 99
SAMPLE OUTPUT
11
17
11
HINT

1≤T,N≤100


0≤R≤100
1≤X≤N
             

题目链接:http://www.ifrog.cc/acm/problem/1106?contest=1014&no=0
分析:这道题就是所谓的签到题,不是很难,能够摧毁的城市是区间 [max(1,X−i),min(X+i,N)],直接输出min(X+i,N)−max(1,X−i)+1即可,题解的那种方式看不太懂,可能是因为我自己没学C++STL,其实就是以一个点为中心,向左区间和右区间分别延伸R个单位,如果超过N或小于0终止!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
int n,r,x;
int a[];
while(scanf("%d",&T)!=EOF)
{
while(T--)
{
scanf("%d%d%d",&n,&r,&x);
memset(a,,sizeof(a));
int ans=;
if(x<=n)
{
for(int i=x;i<=x+r;i++)
{
if(i<=n)
{
a[i]=;
}
}
for(int i=x;i>=x-r;i--)
{
if(i>=)
{
a[i]=;
}
}
for(int i=;i<=n;i++)
if(a[i])
ans++;
printf("%d\n",ans);
}
}
}
return ;
}

给出官方的STL解法:

 #include <cstdio>
#include <algorithm>
int T, N, R, X;
int main()
{
for (scanf("%d", &T); T--; )
{
scanf("%d%d%d", &N, &R, &X);
printf("%d\n", std::min(N, X + R) - std::max(, X - R) + );
}
return ;
}

题目链接:http://www.ifrog.cc/acm/problem/1107?contest=1014&no=1

题解:

下面给出AC代码:

 #include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
const int INF = ;
class Heap
{
private :
std::priority_queue < int, std::vector < int >, std::greater < int > > inc, dec;
void BaseClear()
{
while (!dec.empty() && inc.top() == dec.top())
{
inc.pop();
dec.pop();
}
}
public :
int top()
{
BaseClear();
return inc.top();
}
void del(int x)
{
dec.push(x);
}
void push(int x)
{
inc.push(x);
}
void clear()
{
while (!inc.empty())
inc.pop();
while (!dec.empty())
dec.pop();
}
bool empty()
{
BaseClear();
return inc.empty();
}
}
Q0, Q1;
int TC, f0[], f1[], *F0 = f0 + , *F1 = f1 + , N, C0, C1, N0, N1, E0, E1, TAG0, TAG1;
void forward(char option)
{
if (option == '')
{
F0--;
F0[] = (Q1.empty() ? INF : Q1.top()) + TAG1 - TAG0;
E0++;
Q0.push(F0[]);
while (E0 >= N0)
Q0.del(F0[E0--]);
E1 = ;
Q1.clear();
}
else if (option == '')
{
F1--;
F1[] = (Q0.empty() ? INF : Q0.top()) + TAG0 - TAG1;
E1++;
Q1.push(F1[]);
while (E1 >= N1)
Q1.del(F1[E1--]);
E0 = ;
Q0.clear();
}
else
{
F0--;
F0[] = (Q1.empty() ? INF : Q1.top()) + TAG1 - TAG0;
E0++;
F1--;
F1[] = (Q0.empty() ? INF : Q0.top()) + TAG0 - TAG1;
E1++;
Q0.push(F0[]);
Q1.push(F1[]);
while (E0 >= N0)
Q0.del(F0[E0--]);
while (E1 >= N1)
Q1.del(F1[E1--]);
TAG0 += C0;
TAG1 += C1;
}
}
int main()
{
for (scanf("%d", &TC); TC--; )
{
F0 = f0 + ;
F1 = f1 + ;
TAG0 = TAG1 = ;
Q0.clear();
Q1.clear();
E0 = E1 = ;
scanf("%d%d%d%d%d", &N, &C0, &C1, &N0, &N1);
char c = getchar();
while (c != '' && c != '' && c != '?')
c = getchar();
if (c == '')
{
F0[E0 = ] = ;
Q0.push();
}
else if (c == '')
{
F1[E1 = ] = ;
Q1.push();
}
else
{
F0[E0 = ] = C0;
F1[E1 = ] = C1;
Q0.push(C0);
Q1.push(C1);
}
for (int i = ; i < N; i++)
forward(getchar());
int ans = ;
if (!Q0.empty())
ans = std::min(ans, Q0.top() + TAG0);
if (!Q1.empty())
ans = std::min(ans, Q1.top() + TAG1);
printf("%d\n", ans);
}
return ;
}

题目链接:http://www.ifrog.cc/acm/problem/1108?contest=1014&no=2

题解:

下面给出AC代码:

 #include <bits/stdc++.h>
const int MOD = ;
int F[], N, G, a[], w[];
int gcd(int x, int y)
{
int r;
while (y)
{
r = x % y;
x = y;
y = r;
}
return x;
}
void DP(int x, int y)
{
std::vector < int > Div;
for (int i = ; i * i <= x; i++)
if (x % i == )
{
Div.push_back(i);
if (i * i < x)
Div.push_back(x / i);
}
std::sort(Div.begin(), Div.end());
int L = Div.size();
std::vector < int > Use(L, );
for (int i = L - ; ~i; i--)
{
Use[i] = y / Div[i];
for (int j = i + ; j < L; j++)
if (Div[j] % Div[i] == )
Use[i] -= Use[j];
}
for (int i = G; ~i; i--)
{
F[i] = ;
for (int j = ; j < L && Div[j] <= i; j++)
F[i] = (F[i] + (long long)F[i - Div[j]] * Use[j]) % MOD;
}
}
int main()
{
scanf("%d%d", &N, &G);
for (int i = ; i < N; i++)
scanf("%d", a + i);
for (int i = ; i < N; i++)
scanf("%d", w + i);
F[] = ;
for (int i = ; i < N; i++)
DP(a[i], w[i]);
printf("%d\n", F[G]);
return ;
}

题目链接:http://www.ifrog.cc/acm/problem/1109?contest=1014&no=3

题解:

下面给出AC代码:

 #include <cstdio>
const long long MOD = ;
long long POWER(long long a, long long b)
{
long long r = ;
for (; b; b >>= )
{
if (b & )
r = r * a % MOD;
a = a * a % MOD;
}
return r;
}
long long N;
int T;
int main()
{
for (scanf("%d", &T); T--; )
{
scanf("%lld", &N);
long long F = POWER(, N - ) * - POWER(, N - ) * ;
long long G = POWER(, N - ) * (((N % MOD * ) - ) % MOD) + POWER(, N - ) * (((N % MOD * ) + ) % MOD);
G %= MOD;
F %= MOD;
G %= MOD;
F += MOD;
G += MOD;
F %= MOD;
G %= MOD;
if (G & )
G += MOD;
G >>= ;
printf("%lld %lld\n", F, G);
}
return ;
}

题目链接:http://www.ifrog.cc/acm/problem/1110?contest=1014&no=4

题解:

下面给出AC代码:

 #include <cstdio>
#include <vector>
#include <algorithm>
std::vector < int > E[], col[];
std::vector < std::pair < int, int > > inc[], dec[];
int N, q[], left[], right[], size[], BeiZeng[][], *fa = BeiZeng[], LOG; // left : DFN; right maximum DFN in its subtree
std::vector < int >::iterator ue[];
void DFS()
{
int D = , TIME = ;
q[] = ;
ue[] = E[].begin();
left[] = right[] = ;
while (D)
{
if (ue[D] != E[q[D]].end() && *ue[D] == fa[q[D]])
ue[D]++;
if (ue[D] != E[q[D]].end())
{
int To = *ue[D]++;
fa[To] = q[D];
left[To] = right[To] = ++TIME;
q[++D] = To;
ue[D] = E[To].begin();
}
else
{
if (D > )
right[q[D - ]] = right[q[D]];
D--;
}
}
for (int i = ; i <= N; i++)
size[i] = right[i] - left[i] + ;
while ( << LOG < N)
LOG++;
for (int i = ; i <= LOG; i++)
for (int j = ; j <= N; j++)
BeiZeng[i][j] = BeiZeng[i - ][BeiZeng[i - ][j]];
}
int lowest(int u, int v)
{
for (int i = LOG; ~i; i--)
if (BeiZeng[i][u] && size[BeiZeng[i][u]] < size[v])
u = BeiZeng[i][u];
return u;
}
inline void bar(int u, int d, int l, int r)
{
inc[u].push_back(std::make_pair(l, r));
if (d < N)
dec[d + ].push_back(std::make_pair(l, r));
}
void conflict(int u, int v)
{
if (size[u] < size[v])
std::swap(u, v);
if (left[u] <= left[v] && right[v] <= right[u]) // u is v's ancestor
{
int lw = lowest(v, u);
if (left[lw] > )
{
bar(left[v], right[v], , left[lw] - );
bar(, left[lw] - , left[v], right[v]);
}
if (right[lw] < N)
{
bar(left[v], right[v], right[lw] + , N);
bar(right[lw] + , N, left[v], right[v]);
}
}
else
{
bar(left[u], right[u], left[v], right[v]);
bar(left[v], right[v], left[u], right[u]);
}
}
int MIN[], TAG[], NUM[]; // NUM[] : the number of elements which reach MIN[]
void INC(int p, int l, int r, int L, int R, int w)
{
if (L <= l && r <= R)
{
MIN[p] += w;
TAG[p] += w;
return;
}
if (TAG[p])
{
MIN[p + p] += TAG[p];
MIN[p + p + ] += TAG[p];
TAG[p + p] += TAG[p];
TAG[p + p + ] += TAG[p];
TAG[p] = ;
}
int m = (l + r) >> ;
if (L <= m)
INC(p + p, l, m, L, R, w);
if (R > m)
INC(p + p + , m + , r, L, R, w);
MIN[p] = std::min(MIN[p + p], MIN[p + p + ]);
NUM[p] = (MIN[p + p] == MIN[p] ? NUM[p + p] : ) + (MIN[p + p + ] == MIN[p] ? NUM[p + p + ] : );
}
inline int ZERONUM()
{
return MIN[] == ? NUM[] : ;
}
long long ANS;
void Treeinit(int p = , int l = , int r = N)
{
NUM[p] = r - l + ;
if (l < r)
{
int m = (l + r) >> ;
Treeinit(p + p, l, m);
Treeinit(p + p + , m + , r);
}
}
int main()
{
scanf("%d", &N);
for (int i = , u, v; i < N; i++)
{
scanf("%d%d", &u, &v);
E[u].push_back(v);
E[v].push_back(u);
}
for (int i = , c; i <= N; i++)
{
scanf("%d", &c);
col[c].push_back(i);
}
DFS();
for (int i = ; i <= N; i++)
for (std::vector < int >::iterator x = col[i].begin(); x != col[i].end(); x++)
for (std::vector < int >::iterator y = x + ; y != col[i].end(); y++)
conflict(*x, *y);
Treeinit();
for (int i = ; i <= N; i++)
{
for (std::vector < std::pair < int, int > >::iterator j = inc[i].begin(); j != inc[i].end(); j++)
INC(, , N, j -> first, j -> second, );
for (std::vector < std::pair < int, int > >::iterator j = dec[i].begin(); j != dec[i].end(); j++)
INC(, , N, j -> first, j -> second, -);
ANS += ZERONUM();
}
printf("%lld\n", (ANS - N) >> );
return ;
}

“玲珑杯”ACM比赛 Round #12题解&源码的更多相关文章

  1. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  2. “玲珑杯”ACM比赛 Round #13 题解&源码

    A 题目链接:http://www.ifrog.cc/acm/problem/1111 分析:容易发现本题就是排序不等式, 将A数组与B数组分别排序之后, 答案即N∑i=1Ai×Bi 此题有坑,反正据 ...

  3. “玲珑杯”ACM比赛 Round #1 题解

    A:DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a co ...

  4. “玲珑杯”ACM比赛 Round #12 (D) 【矩阵快速幂的时间优化】

    //首先,感谢Q巨 题目链接 定义状态向量b[6] b[0]:三面临红色的蓝色三角形个数 b[1]:两面临红色且一面临空的蓝色三角形个数 b[2]:一面临红色且两面临空的蓝色三角形个数 b[3]:三面 ...

  5. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  6. “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

    “玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...

  7. “玲珑杯”ACM比赛 Round #1

    Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public ...

  8. “玲珑杯”ACM比赛 Round #18--最后你还是AK了(搜索+思维)

    题目链接   DESCRIPTION INPUT OUTPUT SAMPLE INPUT 1 4 2 1 2 5 2 3 5 3 4 5 5 5 SAMPLE OUTPUT 35 HINT 对于样例, ...

  9. “玲珑杯”ACM比赛 Round #18---图论你先敲完模板(DP+思维)

    题目链接 DESCRIPTION INPUT OUTPUT SAMPLE INPUT 2 3 2 3 5 7 3 10 3 5 7 SAMPLE OUTPUT 12 26 HINT 官方题解: 代码如 ...

随机推荐

  1. Golomb及指数哥伦布编码原理介绍及实现

    2017年的第一篇博文. 本文主要有以下三部分内容: 介绍了Golomb编码,及其两个变种:Golomb-Rice和Exp-Golomb的基本原理 C++实现了一个简单的BitStream库,能够方便 ...

  2. 【Spring-web】AsyncRestTemplate源码学习

    2017-01-23 by 安静的下雪天 http://www.cnblogs.com/quiet-snowy-day/p/6343347.html 本篇概要 类说明 类图 简单例子 精辟的内部类 类 ...

  3. 遍历ul下的li,点击弹出li的索引

    首先我们需要一个html结构 <div > <ul> <li>a</li> <li>a</li> <li>a< ...

  4. 成小胖学习ActiveMQ·基础篇

    过了个春节,回到公司的成小胖变成了成大胖.但是你们千万别以为他那个大肚子里面装的都是肥肉,里面的墨水也多了不少嘞,毕竟成小胖利用春节的半个月时间专心学习并研究了 ActiveMQ,嘿嘿……这不,为了检 ...

  5. (求租仓库)navigationController .navigationBar 的属性设置

    需要做成的效果如下图的

  6. 融云发送手机短信验证短信(.net版本)

    首先本次需求是在MVC5中进行的,通过收费的融云服务来验证手机号码,而且本次的项目也是前后台分离,所以添加了WEBAPI2,那么先添加WEBAPI的接口 using System; using Sys ...

  7. 使用 flow.ci 快速发布你的项目文档

    软件研发的协作过程中,文档是必不可少的一环,有需求文档.接口文档.使用文档等等.当开始写文档时,首先会遇到两个问题: team members 之间如何协作? 文档 OK 后如何分发,去哪里看?如何更 ...

  8. bootstrap_下拉菜单+头部

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. html5橡皮檫特效

    体验效果:http://keleyi.com/keleyi/phtml/html5/32.htm 效果描述: 有点像刮刮卡一样,在移动设备上,把某张图片刮掉显示出另一张图片.效果图如下: 这种刮图的效 ...

  10. 总结ASP.NET MVC Web Application中将数据显示到View中的几种方式

    当我们用ASP.NET MVC开发Web应用程序的时候,我们都是将需要呈现的数据通过"Controllers"传输到"View"当中,怎么去实现,下面我介绍一下 ...