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 ...
随机推荐
- [Android Pro] Android libdvm.so 与 libart.so
reference to :http://blog.csdn.net/koffuxu/article/details/44780351 Android libdvm.so 与 libart.so ...
- iptables配置(/etc/sysconfig/iptables)
iptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables - ...
- [网络流24题]餐巾(cogs 461)
[问题描述] 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,-,N).餐厅可以从三种途径获得餐巾. (1)购买新的餐巾,每块需p分: (2)把用过的餐巾送到快洗部,洗一块需m天,费用需f分 ...
- python基础——使用__slots__
python基础——使用__slots__ 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: cla ...
- BeatifulSoup文档地址
http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html
- Struts2拦截器之ModelDrivenInterceptor
叙述套路: 1.这是个啥东西,它是干嘛用的? 2.我知道它能干啥了,那它咋个用呢? 3.它能跑起来了,但是它是咋跑起来的是啥原理呢? 一.ModelDriven是个啥?他能做什么? 从前端页面到后端的 ...
- NYOJ题目889求距离
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAJ2CAIAAADTwNOXAAAgAElEQVR4nO3dPVLrSteG4W8S5B4IsQ
- Quartus II9.0 使用中文输入的方法
Quartus II可以用中文了 我们都知道高版本的quartus里面不支持中文,就连最新版的10.0也不支持,还好找到了一种方法,和大家分享一下: 具体步骤:quartus ——tools——o ...
- MVC公开课 – 1.基础 (2013-3-15广州传智MVC公开课)
1.MVC设计模式 Model 是指 要处理的业务代码和数据操作代码 View 视图 主要是指的 跟用户打交道 并能够展示数据 Controller 看成是 Model和View的桥梁 优点: 1 ...
- 解析PHP处理换行符的问题 \r\n
一首先说说 \r 与\n的区别回车”(Carriage Return)和“换行”(Line Feed)这两个概念的来历和区别.在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model ...