Codeforces Round #342 (Div. 2)
先买塑料和先买玻璃两者取最大值
#include <bits/stdc++.h> typedef long long ll; int main(void) {
ll n, a, b, c; std::cin >> n >> a >> b >> c;
ll ans = 0;
if (n >= a) {
ll cnt1 = n / a;
ll res = n % a;
if (res >= b) {
cnt1 += (res - b) / (b - c) + 1;
}
ans = std::max (ans, cnt1);
}
if (n >= b) {
ll cnt2 = (n - b) / (b - c) + 1;
cnt2 += (n - cnt2 * (b - c)) / a;
ans = std::max (ans, cnt2);
}
std::cout << ans << '\n'; return 0;
}
暴力 B - War of the Corporations
#include <bits/stdc++.h> const int N = 1e5 + 5;
char str1[N], str2[33]; int main(void) {
scanf ("%s%s", &str1, &str2);
int len1 = strlen (str1);
int len2 = strlen (str2);
int ans = 0;
for (int i=0; i<len1; ++i) {
if (str1[i] == str2[0]) {
bool flag = true;
for (int ii=i+1, j=1; j<len2; ++ii, ++j) {
if (str1[ii] != str2[j]) {
flag = false; break;
}
}
if (flag) {
ans++; i += len2 - 1;
}
}
}
printf ("%d\n", ans); return 0;
}
#include <bits/stdc++.h> int a[502][502]; int main(void) {
int n, k; std::cin >> n >> k;
int now = n * n;
int mx = 0;
for (int i=1; i<=n; ++i) {
for (int j=n; j>=k; --j) {
a[i][j] = now--;
if (j == k) mx += a[i][j];
}
}
for (int i=1; i<=n; ++i) {
for (int j=k-1; j>=1; --j) {
a[i][j] = now--;
}
}
std::cout << mx << '\n';
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) {
std::cout << a[i][j] << ' ';
}
std::cout << '\n';
} return 0;
}
题意:一个数字a + 反过来的ar == n (<=10^100000),已知n,求a
分析:完全看别人代码看懂的。不考虑进位的话,那么n应该是是回文的。那么处理成不进位的,每一位0~18。
#include <bits/stdc++.h> const int N = 1e5 + 5;
char str[N];
char ans[N];
int s[N];
int n; bool judge(void) {
for (int i=0; i<n/2;) {
int l = i, r = n - 1 - i;
if (s[l] == s[r]) ++i;
else if (s[l] == s[r] + 1 || s[l] == s[r] + 11) {
s[l]--; s[l+1] += 10;
}
else if (s[l] == s[r] + 10) {
s[r] += 10; s[r-1]--;
}
else return false;
}
if (n % 2 == 1) {
if (s[n/2] % 2 == 1 || s[n/2] > 18 || s[n/2] < 0) return false;
ans[n/2] = s[n/2] / 2 + '0';
}
for (int i=0; i<n/2; ++i) {
if (s[i] > 18 || s[i] < 0) return false;
ans[i] = (s[i] + 1) / 2 + '0';
ans[n-1-i] = s[i] / 2 + '0';
}
return ans[0] > '0';
} int main(void) {
scanf ("%s", str);
n = strlen (str);
for (int i=0; i<n; ++i) s[i] = str[i] - '0';
if (judge ()) printf ("%s\n", ans);
else if (str[0] == '1' && n > 1) {
for (int i=0; i<n; ++i) {
s[i] = str[i+1] - '0';
}
s[0] += 10; n--;
if (judge ()) printf ("%s\n", ans);
else puts ("0");
}
else puts ("0"); return 0;
}
Codeforces Round #342 (Div. 2)的更多相关文章
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic 贪心
D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...
- Codeforces Round #342 (Div. 2) C. K-special Tables(想法题)
传送门 Description People do many crazy things to stand out in a crowd. Some of them dance, some learn ...
- Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...
- Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)
传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the detai ...
- Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- [USACO07MAR]黄金阵容均衡Gold Balanced L…(洛谷 1360)
题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to na ...
- python基础——高阶函数
python基础——高阶函数 高阶函数英文叫Higher-order function.什么是高阶函数?我们以实际代码为例子,一步一步深入概念. 变量可以指向函数 以Python内置的求绝对值的函数a ...
- EasyUI中控件汉化问题
--BY ZYZ 我在使用EasyUI的过程中,遇到了控件无汉化的情况,如下图. 这么多洋文看着觉得挺烦的.时间居然是月日年格式的,这样可不行,得改. 重写控件代码?别,那能是我这种低级代码C-V客能 ...
- FragmentHelper
package com.icitymobile.anda.util; import java.lang.ref.SoftReference; import java.util.ArrayList; i ...
- hdu1115(计算多边形几何重心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给出一些点,求这些点围成的多边形的重心: 思路: 方法1:直接分别求所有点的x坐标的平均值 ...
- NYOJ之算菜价
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable ...
- C#集合类型
using System; using System.Collections; using System.Collections.Generic; namespace codeTest { class ...
- JSON C# Class Generator ---由json字符串生成C#实体类的工具(转)
转载地址:http://www.cnblogs.com/finesite/archive/2011/07/31/2122984.html json作为互联网上轻量便捷的数据传输格式,越来越受到重视.但 ...
- oracle检查点队列(checkpoint queue)
buffer cache CBC链 按地址链 LRU 干净buffer LRUW 脏buffer 按照冷热 checkpoint queue:链buffer,①链脏块②按buffer第一次脏的时 ...
- 快速熟悉python 下使用mysql(MySQLdb)
首先你需要安装上mysql和MySQLdb模块(当然还有其他模块可以用),这里我就略过了,如果遇到问题自行百度(或者评论在下面我可以帮忙看看) 这里简单记录一下自己使用的学习过程: 一.连接数据库 M ...