solved 4/11

2016 Multi-University Training Contest 8

贪心 1001 Ball(BH)

代码:

#include <bits/stdc++.h>

const int N = 1000 + 5;
std::pair<int, int> a[N];
int n, m; int main() {
int T;
scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) {
int c;
scanf ("%d", &c);
a[i] = {0, c};
}
for (int i=1; i<=n; ++i) {
int c;
scanf ("%d", &c);
for (int j=1; j<=n; ++j) {
if (a[j].second == c && !a[j].first) {
a[j].first = i;
break;
}
}
}
while (m--) {
int l, r;
scanf ("%d%d", &l, &r);
std::sort (a+l, a+r+1);
}
bool flag = true;
for (int i=1; i<=n; ++i) {
if (a[i].first != i) {
flag = false;
break;
}
}
puts (flag ? "Yes" : "No");
}
return 0;
}

物理+微分方程 1006 physics(BH)

代码:

#include <bits/stdc++.h>

int v[100005];

int main() {
int T;
scanf ("%d", &T);
while (T--) {
int n, c;
scanf ("%d%d", &n, &c);
for (int i=1; i<=n; ++i) {
int x, d;
scanf ("%d%d%d", v+i, &x, &d);
}
std::sort (v+1, v+1+n);
int m;
scanf ("%d", &m);
while (m--) {
int t, k;
scanf ("%d%d", &t, &k);
printf ("%.3f\n", sqrt ((double) v[k]*v[k] + 2.0*c*t));
}
}
return 0;
}

线段树+优化 1008 Rikka with Sequence(BH)

代码:(数据加强后TLE)

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5; #define lch o << 1
#define rch o << 1 | 1 ll sum[N<<2], same[N<<2], add[N<<2]; void push_up(int o) {
if (same[lch] == same[rch])
same[o] = same[lch];
else
same[o] = 0;
sum[o] = sum[lch] + sum[rch];
} void push_down1(int o, int l, int r) {
add[lch] += add[o];
add[rch] += add[o];
int mid = l + r >> 1;
sum[lch] += add[o] * (mid-l+1);
sum[rch] += add[o] * (r-mid);
if (same[lch])
same[lch] += add[o];
if (same[rch])
same[rch] += add[o];
add[o] = 0;
} void push_down2(int o, int l, int r) {
same[lch] = same[rch] = same[o];
int mid = l + r >> 1;
sum[lch] = same[o] * (mid-l+1);
sum[rch] = same[o] * (r-mid);
same[o] = 0;
} void build(int o, int l, int r) {
add[o] = 0;
if (l == r) {
scanf ("%I64d", &sum[o]);
same[o] = sum[o];
return ;
}
int mid = l + r >> 1;
build (lch, l, mid);
build (rch, mid+1, r);
push_up (o);
} void modify_add(int o, int l, int r, int ql, int qr, int c) {
if (ql <= l && r <= qr) {
sum[o] += (ll) (r - l + 1) * c;
if (same[o])
same[o] += c;
else
add[o] += c;
return ;
}
if (add[o])
push_down1 (o, l, r);
if (same[o])
push_down2 (o, l, r);
int mid = l + r >> 1;
if (ql <= mid)
modify_add (lch, l, mid, ql, qr, c);
if (qr > mid)
modify_add (rch, mid+1, r, ql, qr, c);
push_up (o);
} void modify_sqrt(int o, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr && same[o]) {
same[o] = (ll) sqrt ((double) same[o]);
sum[o] = same[o] * (r - l + 1);
add[o] = 0;
return ;
}
if (add[o])
push_down1 (o, l, r);
if (same[o])
push_down2 (o, l, r);
int mid = l + r >> 1;
if (ql <= mid)
modify_sqrt (lch, l, mid, ql, qr);
if (qr > mid)
modify_sqrt (rch, mid+1, r, ql, qr);
push_up (o);
} ll query(int o, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) {
return sum[o];
}
if (add[o])
push_down1 (o, l, r);
if (same[o])
push_down2 (o, l, r);
int mid = l + r >> 1;
ll ret = 0;
if (ql <= mid)
ret += query (lch, l, mid, ql, qr);
if (qr > mid)
ret += query (rch, mid+1, r, ql, qr);
return ret;
} int main() {
int T;
scanf ("%d", &T);
while (T--) {
int n, m;
scanf ("%d%d", &n, &m);
build (1, 1, n);
int tp, ql, qr, c;
while (m--) {
scanf ("%d%d%d", &tp, &ql, &qr);
if (tp == 1) {
scanf ("%d", &c);
modify_add (1, 1, n, ql, qr, c);
} else if (tp == 2) {
modify_sqrt (1, 1, n, ql, qr);
} else {
printf ("%I64d\n", query (1, 1, n, ql, qr));
}
}
}
return 0;
}

构造 1011 Rikka with Parenthesis II(BH)

代码:

#include <bits/stdc++.h>

const int N = 1e5 + 5;
char str[N];
int n; bool check() {
if (n & 1)
return false; if (n == 2) {
if (strcmp (str, ")(") != 0)
return false;
} int l = 0, r = 0;
for (int i=0; i<n; ++i) {
if (str[i] == '(')
l++;
else
r++;
}
return l == r;
} int main() {
//freopen ("1011.txt", "r", stdin);
int T;
scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
scanf ("%s", str); //printf ("%s ", str); if (!check ()) {
puts ("No");
continue;
} int top = 0, error = 0, id = -1;
for (int i=0; i<n; ++i) {
if (str[i] == '(') {
top++;
} else {
if (top == 0) {
error++;
id = i;
break;
}
else
top--;
}
} if (!error) {
puts (top == 0 ? "Yes" : "No");
} else {
str[id] = '(';
top = error = 0;
for (int i=0; i<n; ++i) {
if (str[i] == '(') {
top++;
} else {
if (top == 0) {
error++;
break;
}
top--;
}
}
puts (((!error && top == 2) ? "Yes" : "No"));
}
}
return 0;
}

  

2016 Multi-University Training Contest 8的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  3. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  4. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  5. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  6. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  7. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

  8. 2016 Al-Baath University Training Camp Contest-1 F

    Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...

  9. 2016 Al-Baath University Training Camp Contest-1 D

    Description X is well known artist, no one knows the secrete behind the beautiful paintings of X exc ...

  10. 2016 Al-Baath University Training Camp Contest-1 C

    Description Rami went back from school and he had an easy homework about bitwise operations (and,or, ...

随机推荐

  1. Java中的异常

    一.什么是异常 异常就是在程序的运行过程中所发生的不正常的事件,如所需文件找不到,网络连接不通或中断,算术运算出错(如被0除),数组下标越界,装载了一个不存在的类,对null的操作,类型转换异常等等. ...

  2. (源码)自己写的ScrollView里套漂亮的圆角listview(算是漂亮吧。。。)

    找了相关的资料终于写完了: http://blog.csdn.net/jamin0107/article/details/6973845 和 http://emmet1988.iteye.com/bl ...

  3. HLG2081分苹果

    苹果 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 39(24 users) Total Accepted: 29(22 users) ...

  4. 题目1006:ZOJ问题

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:13212 解决:2214 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. ...

  5. jdk新特性

    自动拆装箱子: import org.junit.Test; public class Demo { /* * 自动拆装箱 * */ @Test public void ZhuangXiang() { ...

  6. html css js

    html 回顾 字体:font 属性: color: 颜色 size: 字号 表格:table 标签: tr:表格中的行 td: 单元行中的单元格 th:通常使用在table中的第一行, 成为表头, ...

  7. iOS 网络请求中的challenge

    这里有一篇文章,请阅读,感谢作者!http://blog.csdn.net/kmyhy/article/details/7733619 当请求的网站有安全认证问题时,都需要通过 [[challenge ...

  8. windows8输入法终极完美修复

    现在WIN8正式版出现以来,win8的用户越来越多,毕竟是新系统,BUG肯定是有的,现在小编就为大家解决一个大BUG. 输入法BUG: 现象:1.删除系统输入法,重启后无法调出输入法; 2.卸载用户安 ...

  9. 在iOS开发中,给项目添加新的.framework

    首先需要了解一下iOS中静态库和动态库.framework的概念 静态库与动态库的区别 首先来看什么是库,库(Library)说白了就是一段编译好的二进制代码,加上头文件就可以供别人使用. 什么时候我 ...

  10. 查看TOMCAT的版本

    [root@Apps bin]# sh version.sh Using CATALINA_BASE: /apps/api-tomcat Using CATALINA_HOME: /apps/api- ...