传送门:http://codeforces.com/contest/755

A题题意是给你一个数字n,让你找到一个数字m,使得n*m+1为合数,范围比较小,直接线性筛出1e6的质数,然后暴力枚举一下就好了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e6 + ;
const int INF = 0x3f3f3f3f;
bool prim[maxn];
int main()
{
int n;
int m = sqrt(maxn + 0.5);
for (int i = ; i <= m; i++)
if (!prim[i])
for (int j = i * i; j < maxn; j += i)
prim[j] = ;
prim[] = prim[] = ;
scanf("%d", &n);
for (int i = ; i <= ; i++)
if (prim[i*n+])
{
printf("%d\n", i);
return ;
}
return ;
}

B题题意是A和B玩游戏,A有n个单词,B有m个单词,每个人轮流说一句单词,但是不能说重复的单词,说到最后没得说的人输,A先说,问最后A是否能赢。比较简单的贪心,找出两个人单词中的相同数量,这一部分是必须先讲的,可以处理出AB可以讲的单词数,比较一下大小就可以了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
set <string> s;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
string str;
int same = ;
for (int i = ; i < n; i++)
{
cin >> str;
s.insert(str);
}
for (int i = ; i < m; i++)
{
cin >> str;
if (s.count(str))
same++;
}
int num1 = n - same + (same - same / );
int num2 = m - same + same / ;
if (num1 > num2) puts("YES");
else puts("NO");
return ;
}

C题题意没看懂。。直接看提示大概是给你n个节点,第i个节点和第a[i]个节点在同一棵树上,问有多少棵树。直接并查集或dfs处理出联通块的数量就行了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
int f[maxn];
int find(int x)
{
return f[x] == x ? x : f[x] = find(f[x]);
}
int mix(int x, int y)
{
int fx = find(x), fy = find(y);
if (fx == fy) return ;
f[fx] = fy;
return ;
}
int main()
{
int n, x;
scanf("%d", &n);
int sum = n;
for (int i = ; i <= n; i++) f[i] = i;
for (int i = ; i <= n; i++)
{
scanf("%d", &x);
if(mix(i, x)) sum--;
}
printf("%d\n", sum);
return ;
}

D题是给你n边形,然后每次相隔k个点连上一条边,问每次连边后该n边形一共有多少个面。可以考虑,每连一条边,多出的面数是两点直接线段的数量,所以直接树状数组/线段树统计下走过的点,每次增加的时候直接查询他们之间有多少个点就行了。注意要long long,还有要k=min(k,n-k);不然会多算。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e6 + ;
const int INF = 0x3f3f3f3f;
ll c[maxn];
int n;
int lowbit(int x)
{
return x & (-x);
}
ll getsum(int x)
{
ll ans = ;
while (x > )
{
ans += c[x];
x -= lowbit(x);
}
return ans;
}
void updata(int x)
{
while (x <= n)
{
c[x]++;
x += lowbit(x);
}
}
int main()
{
int k;
scanf("%d%d", &n, &k);
k = min(n - k, k);
ll add = , ans = , cur = ;
for (int i = ; i < n; i++)
{
updata(cur);
if (cur + k <= n) add = getsum(cur + k) - getsum(cur) + ;
else add = getsum(n) - getsum(cur) + getsum((cur + k - ) % n + ) + ;
ans += add;
if (i == n - ) cout << ans - ;
else cout << ans << " ";
cur = (cur + k - ) % n + ;
updata(cur);
// for (int i=1;i<=n;i++)
// cout<<getsum(i)-getsum(i-1)<<" ";
// cout<<endl;
}
return ;
}

这题也可以找规律做。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e6 + ;
const int INF = 0x3f3f3f3f;
int main()
{
ll n, k;
cin >> n >> k;
k = min(k, n - k);
ll c = , add = , ans = ;
for (ll i = ; i <= n; i++)
{
c += k;
if (c > n)
{
add++;
ans += add;
add++;
c %= n;
}
else ans += add;
if (i == n) cout << ans - << " ";
else cout << ans << " ";
}
return ;
}

总结:这次前面的题比较水,虽然是摸黑打的,手速慢了点,好在D没fst掉,升了171分,直接蓝名了,不枉熬夜到4点。可惜没把房间里十几个D题hack掉,终测完发现自己变成房间第一。总之再接再厉。

2017-01-16 15:34:14

8VC Venture Cup 2017 - Elimination Round的更多相关文章

  1. 解题报告8VC Venture Cup 2017 - Elimination Round

    题目链接:http://codeforces.com/contest/755 本蒟蒻做了半天只会做前两道题.. A. PolandBall and Hypothesis 题意:给出n,让你找出一个m, ...

  2. 8VC Venture Cup 2017 - Elimination Round - C

    题目链接:http://codeforces.com/contest/755/problem/C 题意:PolandBall 生活在一个森林模型的环境中,定义森林由若干树组成,定义树为K个点,K-1条 ...

  3. 8VC Venture Cup 2017 - Elimination Round - B

    题目链接:http://codeforces.com/contest/755/problem/B 题意:给定PolandBall 和EnemyBall 这2个人要说的单词,然后每一回合轮到的人要说一个 ...

  4. 8VC Venture Cup 2017 - Elimination Round - A

    题目链接:http://codeforces.com/contest/755/problem/A 题意:给定一个正整数N,问你是否存在一个数M使得N*M+1不是素数(M的范围在[1,1000]). 思 ...

  5. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集

    A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  7. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  8. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  9. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

随机推荐

  1. spark单机部署及样例运行

    spark单机运行部署 环境预装 需要预先下载jdk和spark.机器使用centos6.6(推荐).然后依次运行 [root@spark-master root]# cd /root #安装必要的软 ...

  2. 由自动装箱和拆箱引发我看Integer源码

    背景和问题 在看别人整理的资料时,看到如下一段代码: package com.sitech.test; /** * 自动装箱和拆箱 jdk1.6 * @author liaowp * */ publi ...

  3. django form表单验证

    一. django form表单验证引入 有时时候我们需要使用get,post,put等方式在前台HTML页面提交一些数据到后台处理例 ; <!DOCTYPE html> <html ...

  4. iOS中级篇 - dispatch_semaphore(信号量)的理解及使用

    理解这个概念之前,先抛出一个问题 问题描述: 假设现在系统有两个空闲资源可以被利用,但同一时间却有三个线程要进行访问,这种情况下,该如何处理呢? 没错,这里,我们就可以方便的利用信号量来解决这个问题. ...

  5. 使用highcharts显示mongodb中的数据

    1.mongodb数据表相关 # 显示数据库 show dbs # 数据库 use ceshi # 显示表 show tables # 创建集合 db.createCollection('infoB' ...

  6. 用C++实现斐波那契数列

    我是一个C++初学者,控制台输出斐波那契数列. 代码如下: //"斐波那契数列"V1.0 //李国良于2017年1月12日编写完成 #include <iostream> ...

  7. 实际开发中,后台回传的错误格式的Json数据处理

    现在很多学习刚学习移动开发的同学,相信在培训机构,拿到后台数据的时候,格式都是正确的,甚至有的还是plist文件.但是实际开发中,我们获取数据都是通过网络接口从服务器获取数据,这些数据的格式都是后台写 ...

  8. google的作恶与不作恶

    Google刚刚出现时,那时互联网还似桃花源,路不拾遗夜不闭户,最多升级升级病毒库.Google的发展,从商业模式上带来了广告对互联网无孔不入的渗透,如今Google.百度.阿里等各大巨头都有自己的广 ...

  9. Nuget 学习二

    打包自己的类库 准备工作: 1)nuget 账号: https://www.nuget.org/ 2)nuget 包管理器 点击下载:NuGetPackageExplorer,安装完应该是酱紫. 开始 ...

  10. 冰刃IceSword中文版 V1.22 绿色汉化修正版

    软件名称: 冰刃IceSword中文版 V1.22 绿色汉化修正版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 2.1MB 图片预览: 软件简介: Ic ...