Educational Codeforces Round 10
题意:蜗牛爬树问题;值得一提的是在第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 ;
}
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 ;
}
思路: 离散化+树状数组
离散化:如果数据是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 ;
}
思路:强连通分量
智商太低,无法理解,还是滚去看书去了;
题解连接:
http://www.cnblogs.com/Recoder/p/5323546.html
思路:先做了poj 1852再说;
Educational Codeforces Round 10的更多相关文章
- Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟
A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...
- Educational Codeforces Round 10 D. Nested Segments (树状数组)
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- 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 ...
- 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 ...
- Educational Codeforces Round 10 E - Pursuit For Artifacts (强联通缩点 + 回溯)
题目链接:http://codeforces.com/contest/652/problem/E 给你n个点m个边,x和y双向连接,要是z是1表示这条边上有宝藏,0则没有,最后给你起点和终点,问你要是 ...
- Educational Codeforces Round 10 D. Nested Segments
D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Couchbase之个人描述及入门示例
本文不打算抄袭官方或者引用他人对Couchbase的各种描述,仅仅是自己对它的一点理解(错误之处,敬请指出),并附上一个入门示例. ASP.NET Web项目(其他web开发平台也一样)应用规模小的时 ...
- 29. Populating Next Right Pointers in Each Node && Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node OJ: https://oj.leetcode.com/problems/populating-next-rig ...
- C++学习基础十——子类构造函数与析构函数的执行
1.子类构造函数的执行: 先执行父类的构造函数,再执行成员对象的构造函数,最后执行自身的构造函数. 当继承多个类时,构造函数的 执行顺序与继承时的顺序 相同,而与子类构造函数调用父类构造函数的顺序无关 ...
- C# 特性详解
特性(attribute)是被指定给某一声明的一则附加的声明性信息. 在C#中,有一个小的预定义特性集合. using System; public class AnyClass { [Obsolet ...
- thinkphp实现单图片上传
$config=array( 'maxSize' => 3145728, 'savePath' => './Public/Uploads/', 'rootPath' => './', ...
- SQL笔记-第八章,子查询
一.SELECT列表中的标量子查询 查询每种书籍类型中的最早出版的书籍.在SQL 查询中,需要将一本书籍的出版年份与该类型的所有书籍的出版年份进行比较,并且仅仅在它们匹配时,才返回一个记录 SELEC ...
- Java web--反射(解刨)
本质:先加载类 再解刨类的方法,字段,构造函数 目的:解刨出构造函数 为了new对象 解刨出字段 为了封装数据进去 解刨方法 ...
- C# 接口应用及意义
写在前面:新手入行,读者勉强看看吧,写的不对的欢迎讨论,板砖轻拍! 一.定义 接口描述的是可属于任何类或结构的一组相关功能,所以实现接口的类或结构必须实现接口定义中指定的接口成员. 通常用Interf ...
- 主机名链接数据库,无法生成 SSPI 上下文
两台Server,环境一样,都使用同一域账号. 1的SQL Server可以通过Windows认证连接到2,但2通过Windows认证连接1时报如下错误: 目标主体名称不正确,无法生成 SSPI 上下 ...
- MFCC matlab code
%function ccc=mfcc(x) %归一化mel滤波器组系数 filename=input('input filename:','s'); [x,fs,bits]=wavread(filen ...