On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost aiEgyptian pounds.…
Sagheer and Nubian Market CodeForces - 812C 题意:n个货物,每个货物基础价格是ai. 当你一共购买k个货物时,每个货物的价格为a[i]+k*i. 每个货物只能购买一次.给你s金币,问你最多可以购买多少个货物,这些货物的最小花费. 题解: 直接二分(1~n)购买数量,每次二分都对每个货物计算价格a[i]+mid*i. 结构体对价格排序,mid个货物总价格大于s的时候break并往小二分,否则往大二分. 数据类型开long long. #include <…
题目链接 : http://codeforces.com/problemset/problem/812/C 题意 : 给你 n 件物品和你拥有的钱 S, 接下来给出这 n 件物品的价格, 这些物品的价值不是固定不变的, 价格的变化公式是 a[i]+k*i (i代表第 i 件物品, k 代表你选择买的物品数量, a[i]为物品的底价), 现问你最多能够买多少件物品和所买物品总和, 输出时应该使得所买物品总和尽量小 分析 : 如果我当前能买 k 件物品, 那我肯定能买数量小于 k 的物品, 如果我当…
模拟赛给他们出T1好了~ code: #include <bits/stdc++.h> #define ll long long #define N 100006 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n; ll a[N],ck,A[N],S; int check(int tmp) { int i,cnt=0; for(i=1;i<=n;++i) A[…
C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #define ll long long ll n,s,ai[maxn],ci[maxn]; inline void in(ll &now) { ; ') Cget=getchar(); +Cget-',Cget=getchar(); } int main() { ;i&…
题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and re…
C. Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relat…
C. Sagheer and Nubian Market time limit per test  2 seconds memory limit per test  256 megabytes   On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules.…
CF812C Sagheer and Nubian Market 洛谷评测传送门 题目描述 On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains nn different items numbered from 11 to n…
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost aiEgyptian pounds.…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some str…
傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll a[100010],b[100010],sum; int n,m; bool check(int x){ for(int i=1;i<=n;++i){ b[i]=a[i]+(ll)i*(ll)x; } sum=0; sort(b+1,b+n+1); for(int i=1;i<=x;++i){ s…
http://codeforces.com/contest/812/problem/C [题意] 如何花最少的钱买最多的纪念品?首要满足纪念品尽可能多,纪念品数量一样花钱要最少,输出纪念品数量以及最少花费. 纪念品的价钱是这么定义的:,其中a是基价,k是总共要买的纪念品数量,x是纪念品的index. 题目给出各个纪念品的基价a(当然,x也随之确定) [思路] 二分纪念品数量,判断是否满足题意直接贪心,O(n)算出每个纪念品的价钱,O(nlogn)排序,选出最小的mid个: 二分时间复杂度O(n)…
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; 即为k*i; 这里i是这个物品的下标;(1..n中的某个整数); 然后你有预算S; 问你最多能买多少个物品ans; 并求出买ans个物品的最小花费; [题解] 二分买的物品数量k; 然后就能获取出每个物品的价格了; 即a[i]+i*k; 放到b数组里面; 升序排; 然后选取前k个; 看看超不超预算…
Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He suppo…
根据题意略推一下,其实就是问你满足(a*(a+1))/2 < m <= ((a+1)*a(a+2))/2的a和m-(a*(a+1))/2 -1是多少. 二分求解就行了 #include<cstdio> using namespace std; typedef long long ll; int main() { int T; scanf("%d",&T); ; k <= T; k++){ ll n,m; scanf("%I64d%I64d…
题意:定义两种操作 1 a ---- 向序列中插如一个元素a 2 a b ---- 将序列的前a个元素[e1,e2,...,ea]重复b次插入到序列中 经过一列操作后,为处于某个位置p的元素是多少.数据范围共有105以内的操作,形成序列中的元素总个数大小不超过64bit长整型表示. 思考:只需要记录两种操作这些关键元素的位置,如果查询的坐标位置刚好是第一种产生的,那么直接就知道结果了:如果查询的是第二种操作产生的,它是由前a个元素重复b次而来,它来自前a个元素,依次递归向前找,直到找到第一种情况…
A Sagheer and Crossroads 水题略过(然而被Hack了 以后要更加谨慎) #include<bits/stdc++.h> using namespace std; int main() { //freopen("t.txt","r",stdin); int a[4][4]; //memset(a,0,sizeof(a)); for(int i=0;i<4;i++) for(int j=0;j<4;j++) scanf(&…
C. Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relat…
A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two…
来自FallDream的博客,未经允许,请勿转载,谢谢. 有毒的一场div2 找了个1300的小号,结果B题题目看错没交  D题题目剧毒 E题差了10秒钟没交上去. 233 ------- A.Sagheer and Crossroads 有一个十字路口,分别给出每个方向左右转和直行以及行人的红绿灯的状态,求有没有可能有行人会被车撞 大判断.  附上大佬@ACMLCZH的代码 #include <cstdio> #include <cstring> ][]; inline int…
A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two…
原题链接:http://codeforces.com/problemset/problem/359/D 思路:首先对符合题目的长度(r-l)从0到n-1进行二分查找,对每一个长度进行check,看是否满足条件. 满足条件的话需要区间[l,r]内的最小值和最大公约数相等,如果暴力搜索,会超时,故采用st(sparse table)算法,建立table只需要O(nlgn)时间,查询是O(1),远远小于暴力搜索 st算法具体可参考http://baike.baidu.com/view/1536346.…
E. Simple Skewness time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list…
http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... // #pragma comment(linker, "/STACK:102c000000,102c000000") #include <iostream> #include <cstdio> #include <cstring> #include <sstream>…
这一题的题意是   定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该打个表来存储这种数.那么问题来了,如果要打1~10e18内a的2次方数的表(即1,4,9,16......)需要从1for循环到1e9,明显也会超时.思考后可以发现,如果从3次方起开始打表的话,复杂度就是从1e6开始,不会超时.所以这题,我们打出3.4.5....次方的表.并且用二分的方式找出区间内二次方的数…
Examples input 5 5 1 2 1 2 1 3 10 1 1 1 output 3 5 4 4 3 input 4 4 1 2 3 4 9 1 10 6 output 1 4 4 1 Note In the first example: after the 1-st minute, the 1-st and 2-nd warriors die. after the 2-nd minute all warriors die (and all arrows left over are…
题意:给出n个人(n是奇数),s钱:s为总的可以付工钱的钱: 每一个工人有一个付工钱的区间,只要在这个区间范围内,随便一个数都可以当作给这个工人付了钱: 老板要付给每个工人钱,并且付钱的中位数要尽可能大: 问:最大的中位数是多少: 思路:贪心+思维+二分: 我们以中位数为主体进行二分.那么就需要n/2+1个大于等于中位数的数: 这个时候我们先给钱排序,按第一个数从大到小排: 然后check部分,从1到n遍历,如果满足x在区间范围内,就取x这个数: 那么,为什么就要取这个数呢,因为我们迟早要凑到n…
/* orz claris,这个题的解法非常巧妙,首先是时间问题,其实这个问题只要离线处理一下就可以了,把物品和询问都按照时间排序,然后看一下能不能满足.然后,因为容量<=10^9,显然是不可能开一个这么大的数组,而且这么大一个容量,价值又很小,我们可以考虑用二分解决 对每个询问二分答案,需要判定用容量为 M 的背包是否可 以装下 mid 的价值. 设 fi 表示装了 i 价值所需的最小容量,gi 表示 min(fi,fi+1,fi+2,……). 那么只需要检查 gmid 是否不超过 M 即可.…
Problem B. Market(market.c/cpp/pas)Time limit: 1 secondsMemory limit: 128 megabytes在比特镇一共有 n 家商店,编号依次为 1 到 n.每家商店只会卖一种物品,其中第 i 家商店的物品单价为 ci,价值为 vi,且该商店开张的时间为 ti.Byteasar计划进行m次购物,其中第i次购物的时间为Ti,预算为Mi.每次购物的时候,Byteasar会在每家商店购买最多一件物品,当然他也可以选择什么都不买.如果购物的时间…