A. Splits

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
const long maxn=1e5;
const long mod=1e9+; int main()
{
long n,i;
scanf("%ld",&n);
printf("%ld",+n/);
return ;
}

B. Messages

贪心

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const long maxn=1e5;
const long mod=1e9+; int main()
{
long n,a,b,c,T,t,v,i,sum=;
scanf("%ld%ld%ld%ld%ld",&n,&a,&b,&c,&T);
sum=a*n;
for (i=;i<=n;i++)
{
scanf("%ld",&t);
if (b<=c)
sum=sum+(c-b)*(T-t);
}
cout<<sum<<endl;
return ;
}

C. Alternating Sum

快速幂 求逆元 等比数列

1. 1e9+9不是素数

2. 等比数列,公比可能为0

3. 数的数目为n+1

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const long maxn=1e5;
const long long mod=1e9+;
#define ll long long ll x,y; ll mul(ll s,long ci)
{
ll r=;
while (ci)
{
if ((ci & )==)
r=r*s%mod;
s=s*s%mod;
ci=ci>>;
}
return r;
} void gcd(ll a,ll b)
{
if (b==)
{
x=;
y=;
}
else
{
ll r;
gcd(b,a%b);
r=x;
x=y;
y=r-a/b*y;
}
} ll ni(ll s)
{
gcd(mod,s);
return (y%mod+mod)%mod;
} int main()
{
long n,k,i;
long long a,b,ni_a,ni_a_k,a_k,b_k,sum,c,d;
char ch;
scanf("%ld%lld%lld%ld\n",&n,&a,&b,&k);
c=mul(a,n); b_k=mul(b,k);
a_k=mul(a,k); ni_a=ni(a);
ni_a_k=ni(a_k); sum=;
for (i=;i<=k;i++)
{
scanf("%c",&ch);
if (ch=='+')
sum=(sum+c)%mod;
else
sum=(sum-c+mod)%mod;
} d=(n+)/k;
c=ni_a_k * b_k %mod; if (c==)
printf("%lld",sum*d%mod);
else
printf("%lld",sum* ((mul(c,d)%mod-+mod)%mod) %mod *ni(c-)%mod); return ;
}

D. Destruction of a Tree

树结构,从叶子向根,先确定子节点是否删边,然后父节点是否删边就可以确定,当根节点不删边,则成立,否则不成立

输出删点次序:从叶子向根,遇到需要删边的点,则删边,通过遍历所有的子辈节点,遇到不需要删除边的点,则输出,继续遍历,否则结束

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const long maxn=2e5+;
const long long mod=1e9+;
#define ll long long struct node
{
long d;
struct node *next;
}*point[maxn];
long need[maxn],fa[maxn];
bool vis[maxn],feng[maxn];
long pr[maxn],pr_count=; void dfs(long d)
{
long cc=;
vis[d]=true;
struct node *p=point[d];
while (p)
{
if (!vis[p->d])
{
cc++;
dfs(p->d);
need[d]=need[d] ^ need[p->d];
}
else
fa[d]=p->d;
p=p->next;
}
} void print(long d)
{
printf("%ld\n",d);
struct node *p=point[d];
while (p)
{
if (fa[d]!=p->d && need[p->d]==)
print(p->d);
p=p->next;
}
} void work(long d)
{
struct node *p=point[d];
struct node *q;
while (p)
{
if (fa[d]!=p->d)
work(p->d);
p=p->next;
}
if (need[d]==)
{
printf("%ld\n",d);
p=point[d];
while (p)
{
if (fa[d]!=p->d && need[p->d]==)
print(p->d);
p=p->next;
}
}
} int main()
{
struct node *p;
long n,root,i,y;
scanf("%ld",&n); for (i=;i<=n;i++)
{
point[i]=NULL;
need[i]=; //
vis[i]=false;
}
for (i=;i<=n;i++)
{
scanf("%ld",&y);
if (y==)
root=i;
else
{
p=(struct node *) malloc (sizeof(struct node));
p->d=y;
p->next=point[i];
point[i]=p; p=(struct node *) malloc (sizeof(struct node));
p->d=i;
p->next=point[y];
point[y]=p;
}
}
need[root]=; fa[root]=;
dfs(root);
if (need[root]==)
{
printf("NO");
return ;
} printf("YES\n");
work(root); return ;
}
/*
9
0 1 1 2 2 2 3 6 6 9
0 1 1 1 3 3 3 6 6 5
0 1 2 3 4
*/

CodeForces475的更多相关文章

随机推荐

  1. tee命令详解

    基础命令学习目录首页 参考:http://man.linuxde.net/tee tee命令用于将数据重定向到文件,另一方面还可以提供一份重定向数据的副本作为后续命令的stdin.简单的说就是把数据重 ...

  2. Data truncation: Truncated incorrect DOUBLE value:

    在写sql查询语句queryRunner.update(connection,"update account set balance=? where name=?",account ...

  3. Daily Scrum7 11.11

    今日任务: 徐钧鸿:结束了SQL和Affairs的移植,修改了连接池,学习C#和java的正则表达式并且完成相关的移植 张艺:个人阅读作业 黄可嵩:完成高亮显示的移植,进一步移植搜索代码 徐方宇:继续 ...

  4. Scrum Meeting 11.04

    成员 今日任务 明日计划 用时 徐越 学习Fragment相关知识,代码移植 代码移植 4h 赵庶宏 selvet移植,服务器配置,编写数据库 服务器配置,代码移植 4h 薄霖 学习安卓界面设计数据库 ...

  5. OO第四次作业-对前三次作业总结

    第一次作业由于直接没怎么学过java,全靠一星期速成,前几天看了java的语法,但是因为光看没有打代码,学习效果并不是特别好.由面向过程转向面向对象,不是特别清楚该怎么办,虽然写的是两个类,但实际上是 ...

  6. web14 validation.xml配置 登录验证文件配置

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  7. vs2013 CodeLens

    那东西叫 CodeLens  只有VS2013 旗舰版 (update 2及以上) 才可以用,高级版 专业版都没有.如何打开CodeLens呢?在VS菜单栏 >> 工具 >> ...

  8. IO异常 的处理 test

    package com.throwsss; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFou ...

  9. 我的JAVA运算符理解

    基本概念 原码,反码,补码 只需要记住这几句就够了  1.二进制的最高位是符号位:0表示正数,1表示负数 2.正数的原码,反码,补码都一样 3.负数的反码=它的原码符号位不变,其他位取反 4.负数的补 ...

  10. oh my god 四则运算

    Week1地址:https://git.coding.net/leiqh549/four.git 需求分析: 1.一个生成n道四则运算的程序,要求数字在0-100间,运算符在3-5个之间且运算符至少包 ...