CFRound#379(div2)
题目链接:http://codeforces.com/contest/734
A:SB题。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,num1,num2;
char s[maxn];
int main(){
scanf("%d",&n);scanf("%s",s+1);
for(int i=1;i<=n;i++)if(s[i]=='A')num1++;else num2++;
if(num1>num2)puts("Anton");
else if(num1<num2)puts("Danik");
else puts("Friendship");
return 0;
}
B:SB题。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int k2,k3,k5,k6,sum;
int main(){
scanf("%d%d%d%d",&k2,&k3,&k5,&k6);
sum=256*min(min(k5,k6),k2);
k2-=min(min(k5,k6),k2);
sum+=32*min(k3,k2);
printf("%d\n",sum);
return 0;
}
C:由于题目中第二种魔法是递增的,所以只要枚举第一种魔法用哪一个,二分第二种就好了。。
但我SB的没有看到递增。。所以我把两个都排序后两个指针扫一遍。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200005
using namespace std;
int n,m,k,x,s,mx[maxn];
long long ans;
struct fuck{int x,y;}p1[maxn];
struct pps{int x,y;}p2[maxn];
bool comp(fuck x,fuck y){return x.y<y.y;}
bool cmp(pps x,pps y){return x.y<y.y;}
int read(){
int x=0,f=1;char ch;
for(ch=getchar();ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
int main(){
n=read();m=read();k=read();x=read();s=read();
ans=8e18;
for(int i=1;i<=m;i++)p1[i].x=read();
for(int i=1;i<=m;i++)p1[i].y=read();
for(int i=1;i<=k;i++)p2[i].x=read();
for(int i=1;i<=k;i++)p2[i].y=read();
sort(p1+1,p1+m+1,comp);sort(p2+1,p2+k+1,cmp);
for(int i=1;i<=k;i++)mx[i]=max(mx[i-1],p2[i].x);
p1[0].x=x;
for(int i=0,j=k;i<=m;i++){
while(1ll*p2[j].y+p1[i].y>s&&j>=0)j--;
if(j>=0)ans=min(ans,1LL*max(n-mx[j],0)*p1[i].x);
}
printf("%lld\n",ans);
return 0;
}
D:恶心模拟题。。。(一遍敲对,好爽啊)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a,b,p[9][4];
char s[3];
int read(){
int x=0,f=1;char ch;
for(ch=getchar();ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
int main(){
n=read();a=read();b=read();
for(int i=1,x,y;i<=n;i++){
scanf("%s",s+1);x=read();y=read();int z;
if(s[1]=='R')z=2;else if(s[1]=='B')z=1;else z=3;
if(x==a&&y<b&&(y>p[1][1]||p[1][3]==0))p[1][0]=x,p[1][1]=y,p[1][3]=z;
if(x==a&&y>b&&(y<p[5][1]||p[5][3]==0))p[5][0]=x,p[5][1]=y,p[5][3]=z;
if(y==b&&x<a&&(x>p[3][0]||p[3][3]==0))p[3][0]=x,p[3][1]=y,p[3][3]=z;
if(y==b&&x>a&&(x<p[7][0]||p[7][3]==0))p[7][0]=x,p[7][1]=y,p[7][3]=z;
if(a-x==b-y&&x<a&&(x>p[2][0]||p[2][3]==0))p[2][0]=x,p[2][1]=y,p[2][3]=z;
if(a-x==b-y&&x>a&&(x<p[6][0]||p[6][3]==0))p[6][0]=x,p[6][1]=y,p[6][3]=z;
if(a+b==x+y&&x<a&&(x>p[4][0]||p[4][3]==0))p[4][0]=x,p[4][1]=y,p[4][3]=z;
if(a+b==x+y&&x>a&&(x<p[8][0]||p[8][3]==0))p[8][0]=x,p[8][1]=y,p[8][3]=z;
}
bool bo=0;
if(p[1][3]>1||p[3][3]>1||p[5][3]>1||p[7][3]>1)bo=1;
if(p[2][3]==1||p[2][3]==3||p[4][3]==1||p[4][3]==3||p[6][3]==1||p[6][3]==3||p[8][3]==1||p[8][3]==3)bo=1;
if(bo)puts("YES");else puts("NO");
return 0;
}
E:考虑把同颜色的联通块缩点,那么缩点后一定是黑白相间的。我们可以从直径中间开始变色,那么ans=(直径长度+1)/2.
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200005
using namespace std;
int n,ans,col[maxn],tot,h[maxn],way[maxn*2],Next[maxn*2];
int read(){
int x=0,f=1;char ch;
for(ch=getchar();ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
void insert(int x,int y){way[++tot]=y;Next[tot]=h[x];h[x]=tot;}
int dfs(int x,int fa){
int mx=0,cx=0;
for(int j=h[x];j;j=Next[j])if(way[j]!=fa){
int y=dfs(way[j],x);
if(col[x]!=col[way[j]])y++;
if(y>mx)cx=mx,mx=y;
else if(y>cx)cx=y;
}
ans=max(ans,mx+cx);
return mx;
}
int main(){
n=read();
for(int i=1;i<=n;i++)col[i]=read();
for(int i=1,x,y;i<n;i++){
x=read();y=read();
insert(x,y);insert(y,x);
}
dfs(1,0);printf("%d\n",(ans+1)/2);
return 0;
}
F:只要想到a&b+a|b==a+b就好写了。设sum为sigma{a[i]},则b[i]+c[i]=a[i]*n+sum。把a[i]算出来,再判断是否合法就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200005
using namespace std;
typedef long long ll;
ll n,sum,a[maxn],b[maxn],c[maxn],w[65];
ll read(){
ll x=0,f=1;char ch;
for(ch=getchar();ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
int main(){
n=read();
for(int i=1;i<=n;i++)b[i]=read(),sum+=b[i];
for(int i=1;i<=n;i++)c[i]=read(),sum+=c[i];
if(sum%(2*n)){puts("-1");return 0;}
sum/=2*n;
for(int i=1;i<=n;i++){
if((b[i]+c[i]-sum)%n){puts("-1");return 0;}
a[i]=(b[i]+c[i]-sum)/n;
if(b[i]>n*a[i]||c[i]<n*a[i]){puts("-1");return 0;}
}
for(int i=1;i<=n;i++)
for(int j=0;j<=60;j++)
w[j]+=a[i]>>j&1;
for(int i=1;i<=n;i++){
ll p=0,pp=0;
for(int j=0;j<=60;j++)
if(a[i]>>j&1)p+=w[j]*(1ll<<j),pp+=n*(1ll<<j);
else pp+=w[j]*(1ll<<j);
if(p!=b[i]&&pp!=c[i]){puts("-1");return 0;}
}
for(int i=1;i<=n;i++)printf("%lld ",a[i]);puts("");
return 0;
}
CFRound#379(div2)的更多相关文章
- CFround#380 div2
题目链接:http://codeforces.com/contest/738 A题:SB题. B题:SB题. C题:二分. D题:贪心. E题:乱搞. F题:设f[i][j][k]代表甲先手,左边消去 ...
- bc#54 div2
用小号做的div2 A:竟然看错了排序顺序...白白WA了两发 注意读入一整行(包括空格):getline(cin,st) [gets也是资瓷的 #include<iostream> us ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- 379. Design Phone Directory
379. Design Phone Directory Design a Phone Directory which supports the following operations: get: P ...
- Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
- $('div a') 与$('div>a'),.div+.div2与.div~.div2
$('div a'):div标签下所有层次a元素的jquery对象 $('div>a'):div标签下子元素层次a元素的jquery对象 <body> <div class=' ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforce Round #211 Div2
真的是b到不行啊! 尼玛C题一个这么简单的题目没出 aabbccddee 正确的是aabccdee 我的是 aabcdee 硬是TM的不够用,想半天还以为自己的是对的... A:题... B:题. ...
随机推荐
- Castle.DynamicProxy Part 1: ClassProxy
1.Castle中代理对象的分类 总的来说,代理对象大概可以分为2大类: 1.继承类型的代理对象 一类是继承类型的代理类.即:有一个类A,它的代理类是B.B是继承自A的.调用代理类B中的方法时,可以通 ...
- [置顶] Android事件—单选按键和下拉按键
在平常的开发中单选按键和下拉按键是非常常用的2个点击事件.首先介绍下单选按键 1:单选按键,单选的主键是radiogroup 这个主键也是很重要的 首先介绍下主键的布局 <?xml versio ...
- 为什么选择MongoDB?
为什么选择MongoDB? 阅读目录 开始 为啥用MongoDB? 原来的架构 新需求 如何解决? 新思路 选型条件 一些候选者 最初的选择 代价 新的候选者 重新选择 胆子大一点 胆子再大一点 胆子 ...
- Object-c学习之路十一(NSDate和反射)
挺简单啥也不说了直接上代码(NSDate和反射) // // main.m // NSNumberAndNSValue // // Created by WildCat on 13-7-26. // ...
- asp.net的ajax以及json
asp.net的ajax以及json 来现在这家公司以前,从未接触过webform,以前在学校做的项目是php,java以及asp.net mvc的,当时asp.net mvc用的是razor引擎,所 ...
- sql 数据库还原脚本 (kill链接+独占
在开发过程中经常会碰到数据库还原,要是sql 连接没完全释放掉,那么还原就会受到阻碍.此脚本就是为了解决这个问题. USE [master] GO /****** Object: StoredProc ...
- C# 对象池的实现
C# 对象池的实现 对象池服务可以减少从头创建每个对象的系统开销.在激活对象时,它从池中提取.在停用对象时,它放回池中,等待下一个请求.我们来看下主线程中,如何与对象池打交道: static void ...
- asp.net 上传文件
文件上传实例 公司产品中一直是采用 flash 实现文件上传功能,但用户的需求多了以后遇到了越来越多难以解决的问题,最后试着用硕正提供的freeform.小型页面控件来解决. 硕正文件上传的实现途径有 ...
- tmux tutorial
This is a great tutorial about tmux quick start: http://www.youtube.com/watch?v=wKEGA8oEWXw&nore ...
- 350 - Pseudo-Random Numbers
Pseudo-Random Numbers Computers normally cannot generate really random numbers, but frequently are ...