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的更多相关文章
随机推荐
- Python处理PDF和Word文档常用的方法(二)
Python处理word时,需要安装和导入python-docx模块. 安装命令:pip install python-docx 导入命令:import docx 编码编写顺序:用docx.Docum ...
- iOS静默推送(Silent Remote Notifications)
此功能是iOS7新增加的功能,允许应用收到通知后在后台(background)状态下运行一段代码,可用于从服务器获取内容更新. 普通推送:收到推送后(有文字有声音),点开通知,进入APP后,才执行-- ...
- Scrum Meeting 8 -2014.11.14
给开发加了个pdf信息提取优化任务. 弄了半天发现服务器也是个好东西.这周末可以和爬虫讨论整合的问题了. Member Today’s task Next task 林豪森 协助测试及服务器部署 协助 ...
- java的内存管理机制
1.内存区域的分类 栈内存:基本类型变量和对象的引用,优势在于存取速度快 堆内存:new创建的对象和数组以及对象的实例化变量,优势在于动态分配内存,但是存取速度相对较慢 2.不同类型的内存分配 (1) ...
- 团队计划backlog---DayTwo
任务索引卡(Two): 1. 季方:实现界面跳转,数据库相关数据的显示 的测试: 2. 司宇航:添加部分团队博客,并测试: 3. 王金萱.马佳慧:学习爬虫的相关内容,为将来统计博客部分做准备: ...
- bug排查
有时候让朋友,或者群友,或者同事帮忙看一样困扰你很久的bug会得到意向不到的结果. 因为他们往往不像你,已经在调试代码的过程中被一些东西给束缚了.他们会凭借自己的第一直觉来尝试解决问题,跳过你已经走的 ...
- keil c51笔记
第一章 Keil C51开发系统基本知识 第一节 系统概述 Keil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上.结构性.可读性. ...
- Scrum6.0
一,组员任务完成情况 首页设计初步完成但是需要优化界面,只能简单的输出信息和在首页进行登录.界面极其简单. 鸡汤版面设计有困难,问题在于用何种形式来管理用户的数据上传,但是经过小组间的讨论确定设计方向 ...
- Internet History, Technology and Security (Week 4)
Week 4 History: Commercialization and Growth We are now moving into Week 4! This week, we will be co ...
- [转帖学习]Howto Shrink a Thin Provisioned Virtual Disk (VMDK)
Howto Shrink a Thin Provisioned Virtual Disk (VMDK) Posted by fgrehl on November 24, 2014Leave a com ...