Codeforces 679A Bear and Prime 100】的更多相关文章

链接:传送门 题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后判断这个数是不是素数. 思路:直接打出50以内的素数表,挨个进行询问,用计数器记录出现的因子个数,如果>1则说明为合数,需要特殊处理4,9,16,25,36,49,例如 49 --> 1 7 49 计数器1,但此数仍为合数. /***********************************…
第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std; typed…
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数. #include<bits/stdc++.h> using namespace std; #define ll long long…
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number - an i…
题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the outpu…
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
[题目]A. Bear and Prime 100 [题意]有一数字x,每次可询问一个数字y是否x的因子,最后输出数字x是否素数,要求询问次数<=20. [题解]容易发现[2,100]范围内的非素数一定能分解为[2,47]范围内的素数的乘积,所以只需要询问[2,47]范围内的15个素数. 平方数需要特殊判断,有4,9,16,25,49.(36可以分解为(2*3)^2,不需要特判),恰好20次询问. #include<cstdio> ]={,,,,,,,,,,,,,,,,,,,,}; ];…
C. Bear and Prime 100 time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output This is an interactive problem. In the output section below you will see the information about flushing the output. Bea…
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和,这个sum数组在打素数表时候就能够求出来,注意一点求素数的内层循环要改成i.不能再写成i + i或者i * i了.原因想想就明确了. 这学期最后一场比赛也结束了,结果不非常惬意但也还好. 总的来说这学收获还是蛮多的. 近期可能就不再做ACM了吧,可能要复习CET6了吧,可能要复习期末考试的内容了吧.…
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时…
Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 680C uDebug Description   Input   Output   Sample Input   Sample Output   Hint  …
题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20次问题,每一次询问一个数字x,如果预先选定的隐藏数是x的倍数,则回复"yes",否则回复"no",你只需要判那个数字是否为质数(不一定需要知道具体是多少) 如果一个数字是两个质数积的倍数,则这个数字一定是合数,另外需要注意,两个质数是可以相同的.即如果隐藏数是a*b的倍…
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const int INF=0x3f…
题目链接:http://codeforces.com/problemset/problem/385/C 题目大意:给定n个数与m个询问区间,问每个询问区间中的所有素数在这n个数中被能整除的次数之和 解题思路:首先暴力打出一张素数表,最大的素数小于等于n个数中的最大值即可.在打表的过程就统计从2开始到当前素数的总的整除次数(简直简单粗暴),最后对于询问区间,找出该区间内的最小素数与最大素数在素数表中的位置,结果即为s[r]-s[l-1] 代码如下: #include<cmath> #includ…
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represe…
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample has 3 queries. The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9. The second query comes…
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAX_N = 5000 + 100; char str[MAX_N]; struct Node…
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超过当前剩余体积.问在能选最多个数的情况下,\(X\) 最大是多少 思路 对于每一次选择,首先要保证选完后的剩余体积最大,这样就保证了能选最多个数.然后在这基础上保证 \(X\) 最大. 考虑对于最大的 \(a\),使得 \(a^3<=m\). 如果当前选择的是 \(a\),则剩余体积就是 \(m1…
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q条边,判断加上q条边后,这p个点中的任意一个点对(x,y)是否都满足:能从x走到y,再从y走到x,不经过重复的边.询问强制在线. \((1 ≤ n, q≤ 300 000, 0 ≤ m ≤ 300 000,\sum p \leq 300\ 000,\sum q \leq 300\ 000)\) 分析…
/* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h> #include <iostream> #include <string.h> #define maxn 10000010 using namespace std; int prime[maxn]; int isprime[maxn]; int x[maxn]; void m…
题目链接~~> 做题感悟:这题属于想法题,比赛时直接做的 D 题.可是处理坐标处理的头晕眼花的结果到最后也没AC. 解题思路: 由于查询的时候仅仅考虑素数,so~我们仅仅考虑素数就能够,这就须要筛素数.我们能够在筛素数的同一时候把某个素数出现的倍数加上.输入的时候仅仅要记录某个数的个数就能够了. 代码: #include<iostream> #include<sstream> #include<map> #include<cmath> #include…
[链接] 我是链接,点我呀:) [题意] f[i]表示在x[]中有多少个数字是i的倍数 让你求出sum(f[i]) li<=i<=ri 且i是质数 [题解] 做筛法求素数的时候顺便把素数i在x[]中的倍数的个数求出来就好 前缀和 输出即可 [代码] import java.io.*; import java.util.*; public class Main { static InputReader in; static PrintWriter out; public static void…
A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak…
C. Bear and Different Names time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communicati…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
Bear and Three Balls Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his three fr…
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through…