CodeForces 448
A:Rewards:
题目链接:http://codeforces.com/problemset/problem/448/A
题意:Bizon有a1个一等奖奖杯,a2个二等奖奖杯,a3个三等奖奖杯,b1个一等奖奖牌,b2个二等奖奖牌,b3个三等奖奖牌,和一个有n个架子的橱柜。如今Bizon想把这些奖牌和奖杯放在橱柜里,可是要遵循以下的规则:一个架子上不能同一时候放奖杯和奖牌;一个架子上的奖杯数量不能超过5个。奖牌数量不能超过10个。
问能不能把这些奖杯和奖牌所有放进去。
分析:依照贪心原则。一个架子上放尽可能多的奖杯和奖牌,求出须要多少个架子,与n比較大小就可以。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
int a1, a2, a3, b1, b2, b3, n;
while(~scanf("%d%d%d%d%d%d%d",&a1, &a2, &a3, &b1, &b2, &b3, &n))
{
int suma = a1 + a2 + a3;
int sumb = b1 + b2 + b3;
int cnta = suma / 5, cntb = sumb / 10;
if(suma % 5 != 0)
cnta++;
if(sumb % 10 != 0)
cntb++;
if(cnta + cntb <= n)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
B:Suffix Structures
题目链接:http://codeforces.com/problemset/problem/448/B
题意:给出两个串s和t,问能不能把s变成t,假设能够,输出变换时用的数据结构是什么?变换时能够使用两种数据结构:1.suffix
automaton,它能够删除串中的随意一个字符。2.suffix array,它能够交换串中的随意两个字符。
假设仅仅用到suffix
automaton,输出“automaton“;假设仅仅用到”suffix array“,输出”array“;假设两种都用到,输出”both“;假设变不成。输出“need
tree”。
分析:直接模拟就可以。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
string s, t;
int a[30], b[30];
while(cin >> s >> t)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
if(s.length() < t.length())
{
cout << "need tree" << endl;
continue;
}
int ls = s.length(), lt = t.length();
if(ls == lt)
{
for(int i = 0; i < ls; i++)
{
a[s[i] - 'a']++;
b[t[i] - 'a']++;
}
int flag = 1;
for(int i = 0; i < 26; i++)
if(a[i] != b[i])
{
flag = 0;
break;
}
if(flag)
cout << "array" << endl;
else
cout << "need tree" << endl;
}
else
{
//cout << "s = " << s << ", t = " << t << endl;
for(int i = 0; i < ls; i++)
a[s[i] - 'a']++;
for(int i = 0; i < lt; i++)
b[t[i] - 'a']++;
int flag = 1, ok = 0;
for(int i = 0; i < 26; i++)
if(a[i] < b[i])
{
flag = 0;
break;
}
if(flag)
{
int j, k = 0;
for(int i = 0; i < ls; i++)
{
if(s[i] == t[k])
k++;
if(k == lt)
{
ok = 1;
break;
}
} //t中的字符在s中不一定连续出现,比如ababa abb,应是 aruomaton。比赛时一直Wa在这。 }
if(flag && ok)
cout << "automaton" << endl;
else if(flag && !ok)
cout << "both" << endl;
else
cout << "need tree" << endl;
}
}
return 0;
}
C.Painting Fence
题目链接:http://codeforces.com/problemset/problem/448/C
题意:Bizon要粉刷他的栅栏。栅栏由n块木板组成,每一块有个高度,每次stroke时必须一直接触着栅栏。问最少须要stroke多少次,能够把栅栏刷好。
分析:分治法。
把栅栏从最低处分成左右两部分,每一部分再这样分下去,直到仅仅剩下一块木板。然后往上返回最小值就可以。
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 5005;
int a[MAXN];
int solve(int l, int r, int h)
{
int k = l, mmin = a[l];
if(l > r) return 0;
if(l == r) return a[l] > h;
for(int i = l; i <= r; i++)
if(a[i] < mmin)
{
k = i;
mmin = a[i];
}
return min(r-l+1, solve(l, k-1, mmin) + solve(k+1, r, mmin) + (mmin - h));
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
printf("%d\n", solve(0, n-1, 0));
return 0;
} #include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 5005;
int a[MAXN];
int solve(int l, int r)
{
int k = l;
if(l > r) return 0;
for(int i = l; i <= r; i++)
if(a[i] < a[k])
k = i;
int tmp = a[k];
for(int i = l; i <= r; i++)
a[i] -= tmp;
return min(r-l+1, solve(l, k-1) + solve(k+1, r) + tmp);
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
printf("%d\n", solve(0, n-1));
return 0;
}
D:Multiplication Table
题目链接:http://codeforces.com/problemset/problem/448/D
题意:给出一个n行m列的乘法表,第i行第j列的值为i*j,把这些值从小到大排序,问第k个数是多少。
分析:二分。
#include<iostream>
using namespace std;
typedef long long LL;
LL solve(LL n, LL m, LL k)
{
LL l = 0, r = n * m;
while(r - l > 1)
{
LL mid = (r + l) / 2;
LL sum = 0;
for(int i = 1; i <= n; i++)
{
LL tmp = mid / i;
if(tmp > m) tmp = m;
sum += tmp; //sum为不大于mid的值的个数
}
if(sum >= k) r = mid;
else l = mid;
}
return r;
}
int main()
{
LL n, m, k;
while(cin >> n >> m >> k)
{
cout << solve(n, m, k) << endl;
}
return 0;
}
E:Divisors(dfs)
题目链接:http://codeforces.com/problemset/problem/448/E
题意:给出一个数n,把这个数的因子从小到大写出来,然后对这个数的因子运行k次同样的操作,问最后的结果是什么。假设结果超过100000位。仅仅输出前100000位。
分析:由于对每一个数运行的是同样的操作。所以能够用递归写,当运行到不能分解时,输出一个数,直到运行完k次或者个数已经达到了100000个结束。
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int MAXN = 100000;
LL divisor[MAXN], num;
LL cnt = 0;
void get_divisor(LL x)
{
num = 0;
LL tmp = (LL)sqrt(x);
for(int i = 1; i <= tmp; i++)
{
if(x % i == 0){
divisor[num++] = i;
if(x / i != i)
divisor[num++] = x / i;
}
}
sort(divisor, divisor + num);
} void dfs(LL x, LL k)
{
//cout << "x = " << x << ", k = " << k << endl;
if(cnt >= 100000) return ;
if(k == 0 || x == 1)
{
cout << x << " ";
cnt++;
return ;
}
for(LL i = 0; i < num && divisor[i] <= x; i++)
{
if(x % divisor[i] == 0) {
dfs(divisor[i], k-1);
if(cnt >= 100000) return ;
}
}
} int main()
{
LL x, k;
while(cin >> x >> k)
{
get_divisor(x);
dfs(x, k);
cout << endl;
}
return 0;
}
CodeForces 448的更多相关文章
- Codeforces #448 Div2 E
#448 Div2 E 题意 给出一个数组,有两种类型操作: 选定不相交的两个区间,分别随机挑选一个数,交换位置. 查询区间和的期望. 分析 线段树区间更新区间求和. 既然是涉及到两个区间,那么对于第 ...
- Codeforces 448 D. Multiplication Table
二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...
- Codeforces 448 E. Divisors (DFS,储存结构)
题目链接:E. Divisors 题意: 给出一个X,f(X)是X所有约数的数列(例6:1 2 3 6),给出一个k,k是递归的次数(例:k=2 : f(f(X)) ; X=4,k=2: 1 1 2 ...
- Codeforces 448 D. Multiplication Table 二分
题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...
- Codeforces 448 C. Painting Fence
递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...
- Codeforces Round #448 C. Square Subsets
题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...
- CodeForces:#448 div2 B. XK Segments
传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...
- CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...
- Codeforces Round #448(Div.2) Editorial ABC
被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...
随机推荐
- 保存属性至xml并读取
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...
- codeforces 630P. Area of a Star
题目链接 圆上n个点等距离分布, 求构成的星星的面积. 我们可以求三角形OAB的面积, ∠CAE = 1/2 ∠ COE = PI/n, 那么∠CAO = PI/2n, ∠AOB非常好求, 就是PI/ ...
- poj 3592 Instantaneous Transference 缩点+最长路
题目链接 给一个n*m的图, 从0, 0这个点开始走,只能向右和向下. 图中有的格子有值, 求能获得的最大值. 其中有些格子可以传送到另外的格子, 有些格子不可以走. 将图中的每一个格子都看成一个点, ...
- 四轴飞行器1.2.2 RT-Thread 串口
四轴飞行器1.2.2 RT-Thread 串口 本来是打算说根据RT-Thread的设备管理提供的驱动接口些串口驱动的,但是仔细一看,我去,串口驱动写好了,只需要调用就可以了.下面我们说 ...
- sql发邮件
DROP PROCEDURE USP_CheckProductCodeRepeatAndSendMail go ---检查商家是否有重复的商品编号,如果有则发送给系统配置中接收的用户邮箱 CREATE ...
- 派生类地址比基类地址少4(子类与基类指针强行转换的时候,值居然会发生变化,不知道Delphi BCB是不是也这样) good
大家对虚表并不陌生,都知道每个含有虚函数的类对象都有1个虚指针,但是在现实使用中,却总是因为这而调试半天,才发现原来是虚指针惹的祸.我这几天在调试代码时候也中招了,我的问题是这样的,如下图,CTree ...
- 查GDI对象泄露的利器:GDIView
查GDI对象泄露的利器:GDIView可以很详细的查到进程的GDI对象的总个数,详细的GDI对象的个数,以及其增减数量.其GDI对象类型也可以很详细的得知,以及其内存地址,句柄.实在是好使! 下载地址 ...
- 链表插入排序(insertion-sort-list)
自己写的代码有几个比较大的用例一直过不去,网上的代码大部分有问题,思路是先将链表置空表,再将链表中的元素循环插入到指定位置. 下面是一份正确的代码,但是是带头节点的链表: void Insertsor ...
- 苹果新的编程语言 Swift 语言进阶(六)--函数和闭包
一 .函数 1.1. 函数的定义和调用 函数的定义以funckeyword作为前缀,接着是函数名字,接着跟着一个能够带有參数.也能够不带參数的圆括号.接着用-> 指示函数的返回类型. 函数运行体 ...
- android 视频播放器的INTENT-FILTER属性
<intent-filter> <action android:name="android.intent.action.VIEW&quo ...