Codeforces Round #364
http://codeforces.com/contest/701
水
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
struct node{
int x,y;
node(int x_=,int y_=):x(x_),y(y_){}
bool operator < (const node & a) const{
return x==a.x?y<a.y:x<a.x;
}
}p[];
int n;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&p[i].x);
p[i].y=i;
}
sort(p+,p+n+);
for(int i=;i<=n/;i++){
printf("%d %d\n",p[i].y,p[n-i+].y);
}
return ;
}
题意:起始n*n的矩阵都填满,每次询问,询问的点消除当前点所在行和列的所有物品,输出每次询问后剩下的物品数
思路:如果当前行没有删除过,则现在删除n-(已经删除过的列数)
同理当前列:n-(已经删除过的行数)
如果都没有删除过:两种情况相加+1
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int l[N],r[N];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int cntl=,cntr=;
LL ans;
ans=(LL)n*n;
// cout<<ans<<endl;
while(m--){
int a,b;
scanf("%d%d",&a,&b);
if(r[a]==&&l[b]==){
ans-=(n-cntl+n-cntr-);
cntr++;
cntl++;
r[a]++;
l[b]++;
printf("%I64d ",ans);
continue;
}
if(r[a]==){
ans-=(n-cntl);
cntr++;
r[a]++;
}
if(l[b]==){
ans-=(n-cntr);
cntl++;
l[b]++;
}
printf("%I64d ",ans);
}
return ;
}
题意:计算包含母串中所有不同字母的最小子串长度
思路:设置一个左端点,右端点,判断一下合不合适就可以了
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int m[];
int main(){
int n;
string s;
scanf("%d",&n);
cin>>s;
int l=,r=;
int leng=(int)s.size();
for(int i=;i<leng;i++){
if(m[s[i]]==){
r=i;
}
m[s[i]]++;
}
int ans=inf;
for(int i=r+;i<leng;i++)
m[s[i]]--;
// cout<<"sdf"<<endl;
while(r<leng){
while(m[s[l]]>){
m[s[l]]--;
l++;
}
ans=min(ans,r-l+);
r++;
// cout<<r<<endl;
m[s[r]]++;
}
printf("%d\n",ans);
return ;
}
题意:n个人去距离为l的地方,人的速度为v1 车的速度v2 车一次最多载k个人,求最短时间
思路:一开始想错了,最短时间应该是:车空余的时间越少,不同的人坐车时间和走路时间都一样,且每个人同时到达终点。
推下公式就可以了
难点是最少时间搞不清楚
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int main(){
double l,v1,v2;
int k,n;
scanf("%d%lf%lf%lf%d",&n,&l,&v1,&v2,&k);
double ans=;
int p=n/k;
if(n%k) p++;
double t=l/(p*v2-(v2-v1)/(v2+v1)*v2*(p-));
ans=(l-v2*t)/v1+t;
printf("%.10f\n",ans);
return ;
}
题意:n点节点,n-1条边的树,规定了树上2*k的节点,使这2*k的节点两两配对,求最长长度,每条边长度为1;
思路:
1.以这2*k个节点来看,求树的重心,再求每个点到重心的距离和
2.求每条边的贡献:两个端点所涵盖规定节点数目的最小值 也就是min(a[v],2*k-a[v])
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
#define pb push_back
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int a[N];
vector<int>s[N];
int n,k;
LL ans;
void dfs(int u,int f){
for(int i=;i<(int)s[u].size();i++){
int v=s[u][i];
if(v==f) continue;
dfs(v,u);
a[u]+=a[v];
ans+=min(a[v],*k-a[v]);
}
return;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<*k;i++){
int x;
scanf("%d",&x);
a[x]=;
}
for(int i=;i<=n;i++) s[i].clear();
for(int i=;i<n-;i++){
int x,y;
scanf("%d%d",&x,&y);
s[x].pb(y);s[y].pb(x);
}
ans=;
dfs(,-);
printf("%I64d\n",ans);
return ;
}
Codeforces Round #364的更多相关文章
- Codeforces Round #364 (Div. 2)
这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...
- Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- 树形dp Codeforces Round #364 (Div. 1)B
http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
- Codeforces Round #364 As Fast As Possible
二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #includ ...
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack
B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #364 (Div. 2) Cells Not Under Attack
Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- Codeforces Round #364 (Div. 2) Cards
Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...
- Codeforces Round #364 (Div. 2)->A. Cards
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- MIT算法导论——第四讲.Quicksort
本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...
- Hibernate逍遥游记-第8章 映射组成关系(<component>、<parent>)
一. 1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate ...
- React使用rAF动画介绍
一. <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF ...
- Android Navigation Drawer,自定义ActionBar(标题居中)
整个示例都是改造自 Google Android Training 中的 NavigationDrawer 示例(http://developer.android.com/training/imple ...
- 自定义View(5)Paint常用的一些绘制滤镜,特效等介绍
Shader 返回绘图过程中重复色块的基类 相关方法:Paint::setShader(Shader shader) BitmapShader 从位图加载重复色块 LinearGradient, Ra ...
- c#模拟百度电击器方案
核心提示: 我 们都知道百度对于用户体验很重视,如果一个关键词的某个搜索结果,点击量会很对的话,则百度会认为这个结果是用户所喜欢的结果,然后这个网站自然会在百度 得到一个很好的排名. 网络上也出现了百 ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- RPi 2B Documentation
/********************************************************************** * RPi 2B Documentation * 声明: ...
- 编写爬虫(spider)的预备知识:用java发送HTTP请求
使用原生API来发送http请求,而不是使用apache的库,原因在于这个第三方库变化实在太快了,每个版本都有不小的变化.对于程序员来说,使用它反而会有很多麻烦,比如自己曾经写过的代码将无法复用. 原 ...
- 如何寻找设计灵感?写给刚入行的设计师(转自UI中国)
如何寻找设计灵感?写给刚入行的设计师 如何寻找设计灵感? 这一次的文章,我想和大家聊聊年轻的设计师在没有那么多经验的情况下如何寻找设计师灵感.(希望这篇文章也能帮助感同身受的你) 每个设计师对设计都有 ...