前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了

AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几天

A.A Serial Killer

题目大意:一开始给你两个字符串,每次给你当前两个串中的一个和一个新的串,用新的串换掉旧的,每次输出当前的串。(次数<=1000)

思路:二逼题

#include<iostream>
using namespace std;
int main()
{
string a,b,c,d;int n;
cin>>a>>b>>n;
cout<<a<<' '<<b<<endl;
while(n--)
{
cin>>c>>d;
if(a==c)a=d;else b=d;
cout<<a<<' '<<b<<endl;
}
}

B.Sherlock and his girlfriend

题目大意:给2~n+1染色,要求任意2~n+1中的数,它的质因数(自己除外)和它颜色不同,求最小染色数和方案。(n<=100,000)

思路:质数染成一种,合数染成另一种,特判n<3的情况。

#include<cstdio>
#define MN 100000
int f[MN+];
int main()
{
int n,i,j;
scanf("%d",&n);++n;
for(i=;i*i<=n;++i)if(!f[i])
for(j=i*i;j<=n;j+=i)f[j]=;
puts(n<?"":"");
for(i=;i<=n;++i)printf("%d ",f[i]+);
}

C.Molly's Chemicals

题目大意:给定长度为n的数字序列和一个数k,求序列中有多少子串和为k的次幂。(n<=100,000,1<=|k|<=10)

思路:先预处理出可能用上的k的次幂(要特殊考虑k为±1),把数列前缀和,对于每个si枚举一个k的次幂,求出有多少个j<i满足si-sj=k的次幂,可以用map维护,复杂度O(nlog^2)。

#include<cstdio>
#include<iostream>
#include<map>
#define ll long long
using namespace std;
char B[<<],*S=B,C;int X,F;
inline int read()
{
for(F=;(C=*S++)<''||C>'';)if(C=='-')F=-;
for(X=C-'';(C=*S++)>=''&&C<='';)X=(X<<)+(X<<)+C-'';
return X*F;
}
#define INF 100000000000000LL
map<ll,int> mp;
ll p[];int pn;
int main()
{
fread(B,,<<,stdin);
int n,k,i,j;ll x,ans=;
n=read();k=read();
for(x=;x>=-INF&&x<=INF&&!mp[x];x*=k)p[++pn]=x,mp[x]=;
mp.clear();
for(i=x=;i<n;++i)
{
++mp[x];x+=read();
for(j=;j<=pn;++j)ans+=mp[x-p[j]];
}
cout<<ans;
}

D.The Door Problem

题目大意:N个门,门有初始状态(0/1),M个开关,每个开关可以一次性改变若干的门的开关状态,保证每个门恰被两个开关控制,求是否可能同时打开所有门。(N,M<=100,000)

思路:2-SAT裸题,每个门给对应的两个开关加上一个异或的限制关系,也可以并查集、DFS之类的,总之很水。

#include<cstdio>
char B[<<],*S=B,C;int X;
inline int read()
{
while((C=*S++)<''||C>'');
for(X=C-'';(C=*S++)>=''&&C<='';)X=(X<<)+(X<<)+C-'';
return X;
}
#define MN 100000
#define MV 200000
struct edge{int nx,t;}e[MV*+];
int r[MN+],a[MN+],b[MN+];
int h[MV+],en,l[MV+],d[MV+],cnt,z[MV+],zn,inz[MV+],f[MV+],fn;
inline void ins(int x,int y)
{
e[++en]=(edge){h[x],y};h[x]=en;
e[++en]=(edge){h[y],x};h[y]=en;
}
void tj(int x)
{
l[x]=d[x]=++cnt;inz[z[zn++]=x]=;
for(int i=h[x];i;i=e[i].nx)
{
if(!d[e[i].t])tj(e[i].t);
if(inz[e[i].t]&&l[e[i].t]<l[x])l[x]=l[e[i].t];
}
if(l[x]==d[x])for(++fn;z[zn]!=x;inz[z[zn]]=)f[z[--zn]]=fn;
}
int main()
{
fread(B,,<<,stdin);
int n,m,i,j,k;
n=read();m=read();
for(i=;i<=n;++i)r[i]=read();
for(i=;i<=m;++i)for(j=read();j--;)(a[k=read()]?b[k]:a[k])=i;
for(i=;i<=n;++i)
if(r[i])ins(a[i],b[i]),ins(a[i]+m,b[i]+m);
else ins(a[i],b[i]+m),ins(a[i]+m,b[i]);
for(i=;i<=m<<;++i)if(!d[i])tj(i);
for(i=;i<=m;++i)if(f[i]==f[i+m])return puts("NO"),;
puts("YES");
}

E.The Holmes Children

题目大意:定义f(1)=1,f(n),n>1的值为满足x+y=n且gcd(x,y)=1的(x,y)个数;定义g(n)=Σd|n f(n/d);定义Fk(n)满足k=1时Fk(n)=f(g(n)),k>1且k mod 2=0时Fk(n)=g(Fk-1(n)),k>1且k mod 2=1时Fk(n)=f(Fk-1(n)) 。给出n,k,求Fk(n)mod 1000000007。(1<=n,k<=10^12)

思路:f(n)等同于求满足gcd(x,n-x)=1的x的个数,又因为gcd(x,n-x)=gcd(x,n),所以f(n)就是phi(n)。通过观察发现g(n)=n,所以Fk(n)就是对n做(k+1)/2遍phi。每次n^0.5暴力,n=1时停止就可以了,因为n>2时,phi(n)必为偶数,偶数的phi又必然减少一半,所以复杂度大约是O(n^0.5*logn)。

#include<iostream>
using namespace std;
#define ll long long
#define MX 1000000
ll f[MX+];
ll F(ll x)
{
if(x<=MX)return f[x];
ll i,r=x;
for(i=;i*i<=x;++i)if(x%i==)
{
r=r/i*(i-);
while(x%i==)x/=i;
}
return x>?r/x*(x-):r;
}
int main()
{
ll n,k,i,j;
cin>>n>>k;k=k+>>;
for(i=;i<=MX;++i)f[i]=i;
for(i=;i<=MX;i+=)f[i]>>=;
for(i=;i<=MX;i+=)if(f[i]==i)
for(j=i;j<=MX;j+=i)f[j]=f[j]/i*(i-);
while(n>&&k--)n=F(n);
cout<<n%;
}

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)的更多相关文章

  1. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀

    A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A

    Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...

  3. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT

    题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...

  4. 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem

    再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...

  5. 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...

  6. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D

    Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlo ...

  7. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C

    Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an aff ...

  8. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) B

    Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her s ...

  9. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解 ...

随机推荐

  1. SaaS的那些事儿

    前两年...   大一大二期间,不知道软件架构.云服务器.数据库为何物,偶尔听过却从未用过.天天学的写的东西都是一些命令行代码,所幸在学完<数据结构>和<算法导论>后能够独立实 ...

  2. CPP链表示例

    #include<iostream> #include<stdlib.h> using namespace std; typedef struct Student_data { ...

  3. linux 50个常用命令

    1.ls命令 ls是list的缩写,常用命令为ls(显示出当前目录列表),ls -l(详细显示当前目录列表),ls -lh(人性化的详细显示当前目录列表),ls -a(显示出当前目录列表,包含隐藏文件 ...

  4. 《高级软件测试》Windows平台Jira的配置

    昨天完成了Jira的下载,很开心地去睡觉等明天天亮秒配环境愉快进行使用,撰写文档,开始徜徉于软件管理测试实践,早日走向代码巅峰. 我们把安装和配置的过程来走一遍. 安装完成汤姆猫长这样子: 安装Jir ...

  5. angular4学习笔记整理(二)angular4的路由使用

    这章说一下angular的路由 先说angular路由怎么引入,一开始new出来的angular项目它路由帮你配好了,但看要看app.module.ts里面 1.首先最上面要引入路由模块 import ...

  6. Mysql编译安装详解

    wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz root@Mysql-server ~]# yum install -y c ...

  7. Python内置函数(34)——filter

    英文文档: filter(function, iterable) Construct an iterator from those elements of iterable for which fun ...

  8. openssl几个加密算法使用介绍

    1.openssl简介 1)openssl概述 OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. ...

  9. SpringCloud的DataRest(四)restful特性展示

    一.get - list - http://10.110.20.16:8391/BusiSys/company?page=0&size=5&sort=comp_id,asc 二.pos ...

  10. Angular 学习笔记 ( CDK - Observers )

    <div class="projected-content-wrapper" (cdkObserveContent)="projectContentChanged( ...