【二分或者STL】

二分:

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int K,N,i,cnt=,pos;
scanf("%d%d",&K,&N);
for(i=;i<=N;i++) scanf("%d",&a[i]);
sort(a+,a+N+);
for(i=;i<=N;i++){
pos=lower_bound(a+,a+N+,K-a[i])-a;
if(pos>i&&a[pos]==K-a[i]) printf("%d %d\n",a[i],K-a[i]),cnt++;
}
if(cnt==) puts("No Solution");
return ;
}

set:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int k,n,a[],s,q,flag;
set<int>st;
int main()
{
flag=;
cin>>k>>n;
for(int i=;i<=n;i++)
{
scanf("%lld",&s);
a[i]=s;
st.insert(s);
}
sort(a+,a++n);
set<int>::iterator j;
for(int i=;i<=n;i++)
{
q=k-a[i];
j=st.find(q);
if(j==st.end()) continue;
else{
if(*j>a[i])
{
flag=;
printf("%d %d\n",a[i],*j);
}
}
}
if(flag==) puts("No Solution");
return ;
}

【B:贪心题】

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int N,i,j; ll ans=;
scanf("%d",&N);
for(i=;i<=N;i++) scanf("%d",&a[i]);
sort(a+,a+N+);
for(i=;i<=N;i++) a[i]+=a[i-],ans+=a[i];
printf("%lld\n",ans);
return ;
}

【C:暴力】

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6+;
ll sum[maxn];
bool check(int x)
{
if(x%==) return true;
while(x){
if(x%==) return true;
x/=;
} return false;
}
void solve()
{
for(int i=;i<maxn;i++){
sum[i]=sum[i-];
if(!check(i)) sum[i]+=(ll)i*i;
}
}
int main()
{
solve();
int T,N;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
printf("%lld\n",sum[N]);
}
return ;
}

【D:欧拉函数】

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans;
ll getphi(int x)
{
int res=x;
for(int i=;i*i<=x;i++){
if(x%i==){
res=res/i*(i-);
while(x%i==) x/=i;
}
}
if(x>) res=res/x*(x-);
return res;
}
int main()
{
int N; scanf("%d",&N);
for(int i=;i*i<=N;i++){
if(N%i==) {
ans+=getphi(N/i)*i;
if(i*i!=N) ans+=getphi(i)*(N/i);
}
}
printf("%lld\n",ans);
return ;
}

【E:容斥】

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
int p[maxn+],cnt;
short int vis[maxn+],mu[maxn+];
void read(int &x){
x=; char c=getchar();
while(c>''||c<'') c=getchar();
while(c>=''&&c<='') x=(x<<)+(x<<)+c-'',c=getchar();
}
void Put(ll x)
{
if(x>) Put(x/);
putchar(x%+'');
}
void prime()
{
mu[]=; for(int i=;i<=maxn;i++){
if(!vis[i]) p[++cnt]=i,mu[i]=-;
for(int j=;j<=maxn&&i*p[j]<=maxn;j++){
vis[i*p[j]]=; mu[i*p[j]]=-mu[i];
if(i%p[j]==) { mu[i*p[j]]=; break; }
}
}
}
int a[],num[maxn+];ll ans;
vector<int>G[maxn+];
int main()
{
prime();
int N,Q,x,i,j,Max=;
scanf("%d%d",&N,&Q);
for(i=;i<=N;i++) read(a[i]),Max=max(Max,a[i]),vis[i]=;
for(i=;i<=Max;i++){
for(j=i;j<=Max;j+=i)
G[j].push_back(i);
}
while(Q--){
read(x);
int L=G[a[x]].size();
if(vis[x]==){
for(i=;i<L;i++) num[G[a[x]][i]]--;
for(i=;i<L;i++) ans-=mu[G[a[x]][i]]*num[G[a[x]][i]];
}
else {
for(i=;i<L;i++) ans+=mu[G[a[x]][i]]*num[G[a[x]][i]];
for(i=;i<L;i++) num[G[a[x]][i]]++;
}
vis[x]=vis[x]^;
Put(ans); puts("");
}
return ;
}

【CQ18高一暑假前挑战赛4】标程的更多相关文章

  1. 【CQ18高一暑假前挑战赛5】标程

    [A:暴力] #include<bits/stdc++.h> using namespace std; ; int a[maxn],vis[maxn],N,M; int main() { ...

  2. 【CQ18高一暑假前挑战赛3.5】标程

    [A:快速幂相关] #include<bits/stdc++.h> using namespace std; int qpow(int a,int x){ a%=;; while(x){ ...

  3. 【CQ18高一暑假前挑战赛3】标程

    [A:LCM] #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll a,b, ...

  4. 【CQ18高一暑假前挑战赛2】标程

    [昨晚打校赛,5个小时打完很累了,所以搞忘出题了...对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大] [A:bush博弈] #include<bits/st ...

  5. 【CQ18高一暑假前挑战赛1】标程

    [A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...

  6. [转]关于一些SPFA的标程

    SPFA算法 求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm. 最短路径快速算法-SPFA算法是西南交通大学段凡丁于1994年发表的. 适用范围:给定 ...

  7. [求助][SPOJ MARIOGAM]-高斯消元(内含标程,数据等)

    小蒟蒻开始做概率的题之后,遇到了这道题,然而,他发现自己的程序调试了无数次也无法通过,系统总是返回令人伤心的WA, 于是,他决定把这一天半的时间收集到的资料放在网上, 寻求大家的帮助, 也可以节省后来 ...

  8. hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板

    比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...

  9. 暑假前的flag

    暑假到了,为了简便新开了一个博客,供暑假刷体放一些题解,玩acm1年多了,cf还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...

随机推荐

  1. GOF 23种设计模式-单例模式

    • 创建型模式: – 单例模式.工厂模式.抽象工厂模式.建造者模式.原型模式. • 结构型模式: – 适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模 式. • 行为型模式: – ...

  2. 漫谈深度学习时代点击率预估技术进展 &&深度学习在推荐系统上的发展

    转载:https://www.infoq.cn/article/XA055tpFrprUy*0UBdCb https://www.zhihu.com/question/20830906/answer/ ...

  3. hadoop学习笔记——环境搭建

    基础环境准备: 系统:(VirtualBox) ubuntu-12.04.2-desktop-i386.iso hadoop版本:hadoop-0.20.203.0rc1.tar.gz jdk版本:j ...

  4. 解决Gradle执行命令时报Could not determine the dependencies of task &#39;:compileReleaseJava&#39;.

    Could not determine the dependencies of task ':compileReleaseJava'. > failed to find target andro ...

  5. loarocks install loadcaffe 失败

    loarocks install loadcaffe 失败 1.Error: Your user does not have write permissions in /home/zhangliang ...

  6. 苦逼IT才能看懂的笑话

    这是苦逼IT才能看懂的笑话1.栈和队列的区别是啥? 吃多了拉就是队列:吃多了吐就是栈 2.世界上最遥远的距离不是生与死,而是你亲手制造的BUG就在你眼前,你却怎么都找不到她... 3.<c++程 ...

  7. mysql 查看当前连接数

    http://www.cnblogs.com/pcdelphi/archive/2009/10/31/2017990.html   实战经验: >登录到mysql数据库的终端 >show ...

  8. 【软件创意】智能Goals (android)

    智能Goals  软件创意核心思想:实现你的愿望. 功能概要:帮助记录奋斗了的历程.实现你的愿望.可以是跑步减肥,每天阅读,交际,存钱买房.满足各种记录需要,目标可以是完成多长时间,可以用计时器:可以 ...

  9. caffe搭建--caffe在invidia+cpu 酷睿2Q9300 + ubuntu16.04.2上面的安装和编译过程

    本文原创,转载请注明出处. ------------------------------------------------分割线-------------------------------- 概要 ...

  10. oracle 10g 数据库与客户端冲突导致实例创建无监听问题

    同事在oracle 10g上创建一个实例,快结束时弹出一个错误,提示监听失败之类.查看服务,并无生成监听服务.于是删除重来,一连试了好几次,都是如此. 这真是令人心烦意乱.提示里面有说到端口1521, ...