CodeForces475
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的更多相关文章
随机推荐
- Tesseract 4 自行构建支持双引擎的tessdata 文件
Tesseract 4 版本具备两种识别引擎:新的基于LSTM(神经网络)引擎与传统引擎.通过在初始化时设定不同的EngineMode启动. OCR Engine modes: 0 Legacy en ...
- Appengine直接下载文件并保存到google drive
一直对下载文件比较感兴趣.前些日子无意搜到google 推出一项服务,可以直接将文件下载到google drive中,原型猛戳这里,但有限额限制.一时脑洞大开,可不可以在appengine 上架设服务 ...
- “学霸系统”之NABC
我们团队这次选择的是“学霸系统”客户端项目: 1.需求(need) 作为一款和网上教学问答系统具有相似功能的手机客户端,具体的功能已给出要求:用户管理.搜索.分类.上传下载.用户贡献与交互等功能. ( ...
- Scrum Meeting 10.25
成员 已完成任务 下一阶段任务 用时 徐越 阅读前端代码中和通信相关的部分 学习服务器配置 4h 赵庶宏 阅读前端代码中和通信相关的部分 学习服务器配置 4h 薄霖 继续做UI开发 界面优化 4h 武 ...
- YQCB冲刺周第六天
站立会议如上图 任务看板: 今天的任务为依旧为将用户记录的数据添加到数据库中,以及金额球的设置. 遇到的问题为金额球在jsp页面的显示.
- 09慕课网《进击Node.js基础(一)》HTTP-get/request
get是对request封装 可以在后台发起http请求,获取远程资源,更新或者同步远程资源 http.request(options[,callback]) 以下代码灌水失败: var http = ...
- 项目Beta冲刺(团队)第七天
1.昨天的困难 服务器部署出了问题,本地服务器差点崩掉 运行一直闪退,在查找哪里出现问题的路上一去不复返 2.今天解决的进度 成员 进度 陈家权 消息功能模块 赖晓连 问答功能模块 雷晶 部署服务器到 ...
- C++自学随笔
主要学习内容: 了解了IDE环境的含义 C++与C的区别: 新的数据类型:bool型 新的初始化方法:直接初始化int x(1024) 经过查找,了解了直接初始化与复制初始化的区别:"当用于 ...
- Firefox插件开发学习总结
2018.06.14 我们小组最初只准备开发运行在google上的知乎插件,但我们经过调研发现还有一大部分用户是使用的火狐浏览器,所以我们也准备制作火狐插件.以下是我学习了部分火狐插件制作知识后的总结 ...
- 福大软工 · 第七次作业 - 需求分析报告(404 Note Found队)
目录 组队后的团队项目的整体计划安排 项目logo及思维导图 项目logo 思维导图 产品思维导图 产品思维导图-引导 产品思维导图-后端数据处理.存储 产品思维导图-短信识别 产品思维导图-智能分析 ...