题目链接: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)的更多相关文章

  1. CFround#380 div2

    题目链接:http://codeforces.com/contest/738 A题:SB题. B题:SB题. C题:二分. D题:贪心. E题:乱搞. F题:设f[i][j][k]代表甲先手,左边消去 ...

  2. bc#54 div2

    用小号做的div2 A:竟然看错了排序顺序...白白WA了两发 注意读入一整行(包括空格):getline(cin,st) [gets也是资瓷的 #include<iostream> us ...

  3. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  4. 379. Design Phone Directory

    379. Design Phone Directory Design a Phone Directory which supports the following operations: get: P ...

  5. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  6. $('div a') 与$('div>a'),.div+.div2与.div~.div2

    $('div a'):div标签下所有层次a元素的jquery对象 $('div>a'):div标签下子元素层次a元素的jquery对象 <body> <div class=' ...

  7. SRM 657 DIV2

    -------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforce Round #211 Div2

    真的是b到不行啊! 尼玛C题一个这么简单的题目没出 aabbccddee 正确的是aabccdee 我的是   aabcdee 硬是TM的不够用,想半天还以为自己的是对的... A:题... B:题. ...

随机推荐

  1. Hypeiron Planning/Essbase修改规划类型名称

    1.修改planning关系库 1.1--修改Plan_type,例如将type_name “Plan1”修改为”Plan1ts”,提交 SELECT * FROM hsp_plan_type FOR ...

  2. 简话ASP.NET Web API

    简话ASP.NET Web API 在vs2012中,我们很容易在根据选择的ASP.NET MVC Web应用程序来新建一个Web API应用,聪明的你一定想见得到,Web API和MVC有着某种联系 ...

  3. java中实现与.net的format格式化字符串输出

    Java中的格式化字符串 System.out.println(MessageFormat.format("name={0}", "张三")); .net中的格 ...

  4. 数据访问层的改进以及测试DOM的发布

    数据访问层的改进以及测试DOM的发布 在上一篇我们在宏观概要上对DAL层进行了封装与抽象.我们的目的主要有两个:第一,解除BLL层对DAL层的依赖,这一点我们通过定义接口做到了:第二,使我们的DAL层 ...

  5. 如果gen.lib.rus.ec这个电子书下载站上不去了,那就用这个吧

    如果著名的gen.lib.rus.ec这个电子书下载站上不去了,那就用这个吧: 万千合集站 http://www.hejizhan.com/ 里面除了镜像索引了gen.lib.rus.ec上的所有英文 ...

  6. linux $ 类型变量 及Makefile 中 $ 类型变量的含义

    Shell 命令中: $$: shell pid $!: pid of the last process running in shell $?: shell command return code ...

  7. MVC 5.1的遭遇:“已添加了具有相同键的项”

    ASP.NET MVC 3升级至MVC 5.1的遭遇:“已添加了具有相同键的项”   最近将一个项目从ASP.NET MVC 3升级至刚刚发布的ASP.NET MVC 5.1,升级后发现一个ajax请 ...

  8. github上写个人简历

    随笔- 70  文章- 0  评论- 567  在github上写个人简历——先弄个主页   起因 不知道园友们在使用智联招聘等网站填写简历的时候对要求输入的内容有没有一种无力感,不吐槽了反正就一句话 ...

  9. MAKE gnu

    GNU Make 学习系列一:怎样写一个简单的Makefile 编程通常遵循一个相当简单的程序:编辑源文件,编译源代码成可执行的格式,调试结果.尽管将源代码翻译成可执行程序是常规的过程,如果做的不正确 ...

  10. Repeater 模板中查找子控件

    前言:对于Repeater控件,相信从事NETWeb开发的同仁们再熟悉不过了.因其呈现方式和Literal一样,并不在前端生成任何表单标签元素,所以属于比较轻量级的控件.不过青睐于Repeater的主 ...