A:Gabriel and Caterpillar

题意:蜗牛爬树问题;值得一提的是在第n天如果恰好在天黑时爬到END,则恰好整除,不用再+1;

day = (End - Begin - day0)/(12*(up-down))+1;
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 50005 const double PI = acos(-1.0);
typedef long long LL ; int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
int Begin, End, up, down;
scanf("%d%d%d%d", &Begin, &End, &up, &down);
int day0 = *up;
int day;
if(up-down <= ){
if(End - Begin - day0 <=) day = ;
else day = -;
}else{
if(End - Begin - day0 <=) day = ;
else {
if((End - Begin - day0)%(*(up-down)) == )
day = (End - Begin - day0)/(*(up-down));
else
day = (End - Begin - day0)/(*(up-down))+;
}
}
cout<<day;
return ;
}

B:z-sort

题意:排序题;

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 10005 const double PI = acos(-1.0);
typedef long long LL ; int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
int n, a[N], t[N];
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%d" ,&a[i]);
}
sort(a, a+n);
int i = , j = ;
for(; i < n; i+=, j++)
t[i] = a[j];
for(i = ; i < n; i+=, j++)
t[i] = a[j];
for(int k = ; k < n ; k++) printf("%d ", t[k]);
return ;
}

C:Foe Pairs

ans=总区间数−非法的
经典离线;

所有区间如下:

(1,1),(2,2),(3,3),(4,4),(5,5)……(n,n)

(1,2),(2,3),(3,4),(4,5)……(n-1,n)

(1,3),(2,4),(3,5) ……(n-2,n)

(1,4),(2,5)……(n-3,n)

(1,5)……(n-4,n)

(1,n)

若给出非法对(2,4)

则非法区间是(1,4)与(2,4)以及其下方的所有区间;总数为:(n - 4+1)*(2);

要想在计算区间是不出现重复,则对于所有right值相同的非法对,只取left值最大的;

然后再对right值进行枚举:for:1->n;

ans += 1LL*(z[i]-pos) * (n - i +1);
pos = z[i];

也可以对left枚举;(此时的排序方法与上述不同)
时间复杂度O(nlogn)

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 300005 const double PI = acos(-1.0);
typedef long long LL ;
int a[N], z[N], m, n; int main(){
//reopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
scanf("%d%d", &n, &m);
zero(a);zero(z);
int x;
for(int i = ; i <= n ; i++){
scanf("%d", &x);
a[x] = i;
}
int c,v;
for(int i = ; i <= m; i++){
scanf("%d%d", &c, &v);
int t = max(a[c], a[v]);
z[t] = max(z[t], min(a[c], a[v]));
}
LL ans = , pos = ;
for(int i = ; i<= n ;i++){
if(z[i] -pos >){
ans += 1LL*(z[i]-pos) * (n - i +);
pos = z[i];
}
}
printf("%I64d\n", 1LL*n*(n+)/-ans);
return ;
}

D:Nested Segments

思路: 离散化+树状数组

离散化:如果数据是2,10,1000,100000;则存储所需空间是1e5*4;而离散化存储只需要5*4,

    数据只需要保证其位置不变即可,将2,10,1000,100000用1,2,3,4代替;

    其位置关系,大小关系都不变,但是存储空间变小了;

    这样更方便存储,使得使用树状数组成为可能;

剩下的就是树状数组了:按左区间排下序,然后累计右区间数内区间数;(按左区间从大到小累计,否则,嘿嘿)

时间复杂度:O(nlgn);

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 200005
#define lowbit(k) k&(-k)
const double PI = acos(-1.0);
typedef long long LL ; struct BIT{int l, r, id;};
int bit[N],ANS[N],n;
BIT num[N];
void update(int s, int k){
for(int j = s; j <= n; j +=lowbit(j))
bit[j] += k;
}
int query(int k){
int ans = ;
for(int i = k; i > ; i -=lowbit(i))
ans += bit[i];
return ans;
}
bool compL(BIT a, BIT b){return a.l<b.l;}
bool compR(BIT a, BIT b){return a.r<b.r;}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
scanf("%d",&n);
for(int i = ; i <= n; i++){
scanf("%d%d", &num[i].l, &num[i].r);
num[i].id = i;
}
sort(num+, num+n+, compR);
//for(int i = 1; i <= n; i++) cout<<num[i].l<<" "<<num[i].r<<" "<<num[i].id<<endl;
for(int i = ; i <= n; i++) num[i].r = i;
sort(num+, num+n+, compL);
//for(int i = 1; i <= n; i++) cout<<num[i].l<<" "<<num[i].r<<" "<<num[i].id<<endl;
for(int i = n;i>=; i--){
ANS[num[i].id] = query(num[i].r);
update(num[i].r, );
}
for(int i = ; i <= n; i++) printf("%d\n", ANS[i]);
return ;
}

E:Pursuit For Artifacts

思路:强连通分量

智商太低,无法理解,还是滚去看书去了;

题解连接:

http://www.cnblogs.com/Recoder/p/5323546.html

F:Ants on a Circle

思路:先做了poj 1852再说;

Educational Codeforces Round 10的更多相关文章

  1. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  2. Educational Codeforces Round 10 D. Nested Segments (树状数组)

    题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...

  3. CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组

    题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...

  4. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  5. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  6. Educational Codeforces Round 10 B. z-sort 构造

    B. z-sort 题目连接: http://www.codeforces.com/contest/652/problem/B Description A student of z-school fo ...

  7. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  8. Educational Codeforces Round 10 E - Pursuit For Artifacts (强联通缩点 + 回溯)

    题目链接:http://codeforces.com/contest/652/problem/E 给你n个点m个边,x和y双向连接,要是z是1表示这条边上有宝藏,0则没有,最后给你起点和终点,问你要是 ...

  9. Educational Codeforces Round 10 D. Nested Segments

    D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Windows下单机安装Spark开发环境

    机器:windows 10 64位. 因Spark支持java.python等语言,所以尝试安装了两种语言环境下的spark开发环境. 1.Java下Spark开发环境搭建 1.1.jdk安装 安装o ...

  2. yum install nginx

    先安装nginx的yum源 http://nginx.org/en/linux_packages.html#stable 找到链接,安装: rpm -ivh http://nginx.org/pack ...

  3. [CF245H] Queries for Number of Palindromes (容斥原理dp计数)

    题目链接:http://codeforces.com/problemset/problem/245/H 题目大意:给你一个字符串s,对于每次查询,输入为一个数对(i,j),输出s[i..j]之间回文串 ...

  4. mybaties中在xml中map添加一个list中的判断

    if (uIds.size() > 0) { map.put("uIds", uIds); } else { map.put("uIds", null); ...

  5. tomacat启动慢

    tomcat目录下有多个工程,tomcat每次启动的时候都会去加载,删除不需要的工程,

  6. VMware学习笔记(一)

    vmware核心产品是vSphere,而vSphere主要包括ESXi和vCenterServer. ESXi不依赖其它操作系统OS,安装在每一台物理机上,ESXi是免费的.在ESXi主机上再安装vS ...

  7. PHP的轻量消息队列php-resque使用说明

    日志未经声明,均为AlloVince原创.版权采用『 知识共享署名-非商业性使用 2.5 许可协议』进行许可. 消息队列处理后台任务带来的问题 项目中经常会有后台运行任务的需求,比如发送邮件时,因为要 ...

  8. 6.Mybatis中的动态Sql和Sql片段(Mybatis的一个核心)

    动态Sql是Mybatis的核心,就是对我们的sql语句进行灵活的操作,他可以通过表达式,对sql语句进行判断,然后对其进行灵活的拼接和组装.可以简单的说成Mybatis中可以动态去的判断需不需要某些 ...

  9. position:absolute、float、display:inline-block 区别

    position: absolute会导致元素脱离文档流,被定位的元素等于在文档中不占据任何位置,在另一个层呈现,可以设置z-index.PS的图层效果就是position: absolute. fl ...

  10. afterTextChanged() callback being called without the text being actually changed

    afterTextChanged() callback being called without the text being actually changed up vote8down votefa ...