A. Hard to prepare

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+;
long long bit[];
long long f[]; int main() {
int T;
int n,k;
bit[] = ;
for (int i = ; i <= ; i++) {
bit[i] = *bit[i-]%MOD;
}
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
f[] = bit[k];
long long t1 = (bit[k]-+MOD)%MOD;
long long t2 = (bit[k]-+MOD)%MOD;
f[] = f[]*t1%MOD;
for (int i = ; i <= n; i++) {
f[i] = (f[i-]*t1%MOD+(f[i-]-f[])*t2%MOD)%MOD;
f[i] = (f[i] + MOD)%MOD;
}
printf("%d\n", (int)f[n]);
}
return ;
}

B. BE, GE or NE

#include <bits/stdc++.h>
using namespace std; int n;
int dp[][];
int a[][];
const int INF = 0x3f3f3f3f; int gao(int i, int now) {
if (i >= n) return now-;
if (dp[i][now] != INF) {
return dp[i][now];
}
if (i% == ) {
int ans = -;
int tmp = now-;
if (a[i][] > ) {
int nn = min(tmp+a[i][], );
ans = max(ans, gao(i+, nn+));
}
if (a[i][] > ) {
int nn = max(tmp-a[i][], -);
ans = max(ans, gao(i+, nn+));
}
if (a[i][] > ) {
ans = max(ans, gao(i+, -tmp+));
}
dp[i][now] = ans;
return ans;
} else {
int ans = ;
int tmp = now-;
if (a[i][] > ) {
int nn = min(tmp+a[i][], );
ans = min(ans, gao(i+, nn+));
}
if (a[i][] > ) {
int nn = max(tmp-a[i][], -);
ans = min(ans, gao(i+, nn+));
}
if (a[i][] > ) {
ans = min(ans, gao(i+, -tmp+));
}
dp[i][now] = ans;
return ans;
}
} int main() {
int m,k,l;
while(scanf("%d%d%d%d", &n, &m, &k, &l) == ) {
for (int i = ; i < n; i++) {
scanf("%d%d%d", &a[i][], &a[i][], &a[i][]);
}
for (int i = ; i <= n; i++)
for (int j = ; j <= ; j++)
dp[i][j] = INF;
int ans = gao(, m+);
if (ans >= k)puts("Good Ending");
else if(ans <= l) puts("Bad Ending");
else puts("Normal Ending");
}
return ;
}

C. Cacti Lottery

#include <bits/stdc++.h>
using namespace std; int getScore(int s) {
switch(s) {
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
}
} char mp[][]; int a[][]; double sum;
double num; long long cnt = ;
double r[];
double c[];
double dd[]; void gao(bool used[], int x, int y) {
/*
if (x >= 3) {
printf("*** x %d y %d\n",x, y);
for (int i = 1; i <= 9; i++)
printf("%d ", used[i]);
printf("\n");
for(int i = 0; i < 3; i++) {
for(int j = 0;j < 3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
}
*/ if (x >= ) {
for (int i = ; i < ; i++) {
int tmp = ;
for (int j = ; j < ; j++)
tmp += a[i][j];
r[i] += getScore(tmp);
}
for (int j = ; j < ; j++) {
int tmp = ;
for (int i = ; i < ; i++) {
tmp += a[i][j];
}
c[j] += getScore(tmp);
}
dd[] += getScore(a[][] + a[][] + a[][]);
dd[] += getScore(a[][] + a[][] + a[][]);
cnt++;
return;
}
int nx = x;
int ny = y+;
if (ny >= ) {
ny = ;
nx++;
}
if (mp[x][y] != '#') {
gao(used, nx, ny);
} else {
for (int i = ; i <= ; i++) {
if (!used[i]) {
used[i] = true;
a[x][y] = i;
gao(used, nx, ny);
a[x][y] = ;
used[i] = false;
}
}
}
} void dfs(bool used[], int x, int y) {
/*
if (x >= 3) {
printf("x %d y %d\n",x, y);
for (int i = 1; i <= 9; i++)
printf("%d ", used[i]);
printf("\n");
for(int i = 0; i < 3; i++) {
for(int j = 0;j < 3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
}
*/
if (x >= ) {
cnt = ;
for (int i = ; i < ; i++) {
r[i] = ;
c[i] = ;
}
dd[] = ;
dd[] = ;
gao(used, , );
double tmp = ;
for (int i = ; i < ; i++) {
tmp = max(tmp, r[i]);
tmp = max(tmp, c[i]);
}
tmp = max(tmp, dd[]);
tmp = max(tmp, dd[]);
sum += tmp/cnt;
num += ;
return;
}
int nx = x;
int ny = y+;
if (ny >= ) {
nx++;
ny = ;
}
if (mp[x][y] != '*') {
dfs(used, nx, ny);
} else {
for (int i = ; i <= ; i++) {
if (!used[i]) {
used[i] = true;
a[x][y] = i;
dfs(used, nx, ny);
a[x][y] = ;
used[i] = false;
}
}
}
} int main() {
int T;
scanf("%d", &T);
while (T--) {
for (int i = ; i < ; i++)
scanf("%s", mp[i]);
sum = ;
num = ;
bool used[];
memset(used, false, sizeof(used));
memset(a, , sizeof(a));
for(int i = ; i < ; i++)
for (int j = ; j < ; j++) {
if (mp[i][j] >= '' && mp[i][j] <= '') {
used[mp[i][j] -''] = true;
a[i][j] = mp[i][j]-'';
}
}
dfs(used, , );
printf("%.10f\n", sum/num);
}
return ;
}

D. Easy Math

E. End Fantasy VIX

F. Features Track

#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>;
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + ; int t;
int n, m;
pair<int,int>s;
map<pair<int, int>, int>sum;
map<pair<int, int>, int>flag;
set<pair<int,int> >v; int main()
{
scanf("%d", &t);
while(t--)
{
int ans = ;
v.clear();
sum.clear();
scanf("%d", &n);
while(n--)
{
flag.clear();
scanf("%d", &m);
if(m == )
{
v.clear();
sum.clear();
}
for(int i = ; i < m; i++)
{
int a, b;
scanf("%d %d", &a, &b);
s.first = a;
s.second = b;
if(!flag[s])
sum[s]++;
flag[s] = ;
v.insert(s);
ans = max(ans, sum[s]);
}
pair<int, int> cnt[];
int d = ;
for(set<pair<int,int> >::iterator it = v.begin();it != v.end();it++)
{
if(flag[*it] == )
cnt[d++] = *it;
}
for(int i = ; i < d; i++)
{
v.erase(cnt[i]);
sum[cnt[i]] = ;
}
}
printf("%d\n",ans);
}
return ;
}

G. Trace

#include <bits/stdc++.h>
using namespace std; long long gao(vector<int> vec) {
int sz = vec.size();
set<int>st;
long long ans = ;
for (int i = sz-; i >= ; i--) {
set<int>::iterator it = st.lower_bound(vec[i]);
if (it == st.begin()) {
ans += vec[i];
} else {
it--;
ans += vec[i] - *it;
}
st.insert(vec[i]);
}
return ans;
}
int main() {
int n;
while(scanf("%d", &n) == ) {
vector<int>vec1, vec2;
int x,y;
while(n--) {
scanf("%d%d", &x, &y);
vec1.push_back(x);
vec2.push_back(y);
}
cout<<gao(vec1) + gao(vec2)<<endl;
}
}

H. Ryuji doesn't want to study

#include <iostream>
#include <stdio.h>
#define ll long long
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
int n;
const int MAXN = 1e5 + ;
ll sum[MAXN << ];
ll add[MAXN << ]; void push_up(int rt){//向上更新
sum[rt] = sum[rt << ] + sum[rt << | ];
} void push_down(int rt, int m){
if(add[rt]){//若有标记,则将标记向下移动一层
add[rt << ] += add[rt];
add[rt << | ] += add[rt];
sum[rt << ] += (m - (m >> )) * add[rt];
sum[rt << | ] += (m >> ) * add[rt];
add[rt] = ;//取消本层标记
}
} void build(int l, int r, int rt){//建树
add[rt] = ;
if(l == r){
scanf("%lld", &sum[rt]);
return;
}
int mid = (l + r) >> ;
build(lson);
build(rson);
push_up(rt);//向上更新
} void update(int L, int R, ll key, int l, int r, int rt){//区间更新
if(L <= l && R >= r){
sum[rt] = (r - l + ) * key;
add[rt] = key;
return;
}
push_down(rt, r - l + );//向下更新
int mid = (l + r) >> ;
if(L <= mid) update(L, R, key, lson);
if(R > mid) update(L, R, key, rson);
push_up(rt);//向上更新
} ll query(int L, int R, int l, int r, int rt){//区间求和
if(L <= l && R >= r) return sum[rt];
push_down(rt, r - l + );//向下更新
int mid = (l + r) >> ;
ll ans = ;
if(L <= mid) ans += query(L, R, lson);
if(R > mid) ans += query(L, R, rson);
return ans;
}
//-----------------------------------
ll sum2[MAXN << ];
ll add2[MAXN << ]; void push_up2(int rt){//向上更新
sum2[rt] = sum2[rt << ] + sum2[rt << | ];
} void push_down2(int rt, int m){
if(add2[rt]){//若有标记,则将标记向下移动一层
add2[rt << ] += add2[rt];
add2[rt << | ] += add2[rt];
sum2[rt << ] += (m - (m >> )) * add2[rt];
sum2[rt << | ] += (m >> ) * add2[rt];
add2[rt] = ;//取消本层标记
}
} void build2(int l, int r, int rt){//建树
add2[rt] = ;
if(l == r){
sum2[rt]=sum[rt]*(n-l+);
return;
}
int mid = (l + r) >> ;
build2(lson);
build2(rson);
push_up2(rt);//向上更新
} void update2(int L, int R, ll key, int l, int r, int rt){//区间更新
if(L <= l && R >= r){
sum2[rt] = (r - l + ) * key;
add2[rt] = key;
return;
}
push_down2(rt, r - l + );//向下更新
int mid = (l + r) >> ;
if(L <= mid) update2(L, R, key, lson);
if(R > mid) update2(L, R, key, rson);
push_up2(rt);//向上更新
} ll query2(int L, int R, int l, int r, int rt){//区间求和
if(L <= l && R >= r) return sum2[rt];
push_down2(rt, r - l + );//向下更新
int mid = (l + r) >> ;
ll ans = ;
if(L <= mid) ans += query2(L, R, lson);
if(R > mid) ans += query2(L, R, rson);
return ans;
} int main(void){
int m;
scanf("%d%d", &n, &m);
build(, n, );
build2(, n, );
while(m--){
ll x, y;
ll z;
scanf("%lld%lld%lld",&x,&y,&z);
if(x==){
ll ans=query(y,z,,n,);
ll ans2=query2(y,z,,n,);
printf("%lld\n",ans2-ans*(n-z));
}else{
update(y,y,z,,n,);
update2(y,y,z*(n-y+),,n,);
}
}
}

I. Characters with Hash

#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + ; int t;
int n;
char ch[];
string str; int main()
{
scanf("%d", &t);
while(t--)
{
int num;
ll ans = ;
int cnt = ;
scanf("%d %s", &n, ch);
cin>>str;
int len = str.size();
int flag=;
for(int i = ;i < len; i++)
{
num = abs(str[i]- ch[]);
if(flag==) {
if (num != ) {
if (num / == ) {
ans += ;
} else if (num / == ) {
ans += ;
}
flag = ;
}
}else{
ans+=;
}
}
if(ans == )
ans++;
printf("%lld\n",ans);
}
return ;
}

J. Maze Designer

#include <bits/stdc++.h>
using namespace std; const int MAXN = ;
const int DEG = ; struct Edge{
int to,next;
int w;
}edge[MAXN*];
int head[MAXN],tot;
void addedge(int u,int v, int w){
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].w = w;
head[u] = tot++;
}
void init(){
tot = ;
memset(head,-,sizeof(head));
}
int fa[MAXN][DEG];//`fa[i][j]琛ㄧず缁撶偣i鐨勭`2^j`涓鍏坄
int deg[MAXN];//`娣卞害鏁扮粍` void BFS(int root){
queue<int>que;
deg[root] = ;
fa[root][] = root;
que.push(root);
while(!que.empty()){
int tmp = que.front();
que.pop();
for(int i = ;i < DEG;i++)
fa[tmp][i] = fa[fa[tmp][i-]][i-];
for(int i = head[tmp]; i != -;i = edge[i].next){
int v = edge[i].to;
if(v == fa[tmp][])continue;
deg[v] = deg[tmp] + ;
fa[v][] = tmp;
que.push(v);
} }
}
int LCA(int u,int v){
if(deg[u] > deg[v])swap(u,v);
int hu = deg[u], hv = deg[v];
int tu = u, tv = v;
for(int det = hv-hu, i = ; det ;det>>=, i++)
if(det&)
tv = fa[tv][i];
if(tu == tv)return tu;
for(int i = DEG-; i >= ; i--){
if(fa[tu][i] == fa[tv][i])
continue;
tu = fa[tu][i];
tv = fa[tv][i];
}
return fa[tu][];
} struct Node {
int u,v,w;
}node[];
bool cmp(Node a, Node b) {
return a.w > b.w;
} int F[];
int find(int x) {
if(F[x] == -)return x;
else return F[x] = find(F[x]);
}
void bing(int x, int y) {
int t1 = find(x);
int t2 = find(y);
if (t1 != t2)F[t1] = t2;
} int main() {
int n,m;
while(scanf("%d%d", &n, &m) == ) {
int cnt = ;
for (int i = ; i < n; i++)
for (int j = ; j < m; j++) {
int u = i*m + j;
char op[];
int w;
for(int t = ; t<; t++) {
scanf("%s%d", op, &w);
if (op[] == 'X')continue;
int v;
if (op[] == 'D' && i < n-) {
v = (i+)*m + j;
} else if (op[] == 'R' && j < m-) {
v = i*m+j+;
} else {
continue;
}
node[cnt].u = u;
node[cnt].v = v;
node[cnt++].w = w;
}
}
sort(node, node+cnt, cmp); init();
memset(F, -, sizeof(F));
for (int i = ; i < cnt; i++) {
int u = node[i].u;
int v = node[i].v;
if (find(u) != find(v)) {
bing(u, v);
addedge(u,v,node[i].w);
addedge(v,u,node[i].w);
}
}
BFS(); int Q;
scanf("%d", &Q);
int x1,y1,x2,y2;
while(Q--) {
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int u = (x1-)*m+y1-;
int v = (x2-)*m + y2-;
int lca = LCA(u,v);
printf("%d\n", deg[u]+deg[v] - *deg[lca]);
} return ; }
return ;
}

K. Morgana Net

ACM-ICPC 2018 徐州赛区网络预赛的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  3. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和

    链接 https://nanti.jisuanke.com/t/31456 参考题解  https://blog.csdn.net/ftx456789/article/details/82590044 ...

  10. ACM-ICPC 2018 徐州赛区网络预赛(8/11)

    ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...

随机推荐

  1. DB2去重的几种方法

    有两个意义上的重复记录,一是完全重复的记录,也即所有字段均重复的记录,二是部分关键字段重复的记录,比如Name字段重复,而其他字段不一定重复或都重复可以忽略. 例如下表:table1 用户办理套餐的记 ...

  2. Chart.js: 一个简单的 JS Chart Library

    Chart.js 是一个 Open Source 的 JavaScript Chart Library.它一共有 6 中 Chart,全都是 HTML5 based. 底下是 Chart.js 所提供 ...

  3. Int与String之间相互转换

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  4. bootstrap Table的 一些小操作

    function HQCreatTable(ob) { var option = { cache: false,//是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*) scroll ...

  5. 爬虫爬取代理IP池及代理IP的验证

    最近项目内容需要引入代理IP去爬取内容. 为了项目持续运行,需要不断构造.维护.验证代理IP. 为了绕过服务端对IP 和 频率的限制,为了阻止服务端获取真正的主机IP. 一.服务器如何获取客户端IP ...

  6. hdu-1233 还是畅通工程---MST模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1233 题目大意: 求MST最小生成树 解题思路: Prim算法直接套即可 #include<b ...

  7. 【51nod1815】调查任务(Tarjan+拓扑)

    点此看题面 大致题意:有\(N\)个城市由\(M\)条单向道路(图不一定联通),每个城市有一个发达程度\(a[i]\),要求你求出首都\(S\)到城市\(i\)的一条路径上的两个不同城市\(x,y\) ...

  8. 使用jquery实现获取除this(当前选定)以外的元素

    今天做项目时,要求完成功能评价的分类,即好评,差评,中评.遇到一个问题,如何在选定一个评论类型时,该div颜色改变,其他评论类型的div颜色不变. 在使用$(this).attr()时,表示当前元素的 ...

  9. 巧妙使用JQuery Clone 添加多行数据,并更新到数据库

    WEB代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchAdd. ...

  10. JQuery根据关键字检索html元素并筛选显示

    背景:标题比较唬人,实际上就是在文本框中输入关键字,通过关键字检索html元素,筛选后显示在界面上. Html元素如下: <div> <input type="text&q ...