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 ...
随机推荐
- 115、定时器(TimerTask+Timer+Handler)
public class TimerUtils { public static Activity act; public static List<MaiDianModels> listMa ...
- IRaster、IRasterlayer、IRasterdataset之间的转换
IRaster.IRasterlayer.IRasterdataset之间的转换 layer = axMapControl.get_Layer(0);//需要的栅格图层 IRasterLayer ra ...
- Android 使用 ksoap2-android 访问WebService(C#)
Android 客户端与后台数据交互的方式有很多种.今天这里记录一下,与WebService的数据交互. 新建一个简单的WebService 创建方式如下: 创建好的项目是这样的. 我们在里面写几句简 ...
- SQL笔记 [长期更新] (-2015.4)
[遍历所有表,复制表结构,复制表数据] --插入语句SELECT * INTO A FROM B 是在还没有A表的情况下,直接通过B表创建并把B表数据复制到A表里面,之后A,B表的结构和数据完全一样. ...
- Windows:文件服务器,访问进去不能查看到完整的文件
文件服务器,访问进去不能查看到完整的文件:别人访问却可以查看到完整的所有文件 可能是登录的帐号串掉导致,删除文件服务器帐号,重新访问: cmd: net use /delete *
- CGI、FastCGI和PHP-FPM浅析
这段时间对Nginx+PHP-FPM的概念和机制一直不太清晰,趁着同事的分享和看过的几篇博文和资料,重新将思路处理一下. 首先,PHP-FPM(FastCGI Process Manager: Fas ...
- 常用freemarker使用文档
设置价格格式 <#setting number_format = "currency" /> <#assign price = 42 /> ${price} ...
- XidianOJ 1176 ship
题目描述 The members of XDU-ACM group went camp this summer holiday. They came across a river one day. T ...
- css3 3d效果及动画学习
css参考手册: http://www.phpstudy.net/css3/ http://www.css88.com/book/css/ 呈现3d效果:-webkit-transform-style ...
- 关于UID和GID的创建、修改、删除;简要举例
用户.组和权限 安全3A资源分派 (authentication)认证 (authorization)授权 (accounting)审计 user( 用户) Linux用户:Username/UID ...