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] adb 命令 dumpsys activity , 用来看 task 中的activity。 (uninstall virus)
用“adb shell dumpsys activity”命令再来查看一下系统运行的的任务,就会看到: ACTIVITY MANAGER ACTIVITIES (dumpsys activity ac ...
- 解决passwd 为普通用户设密码 不成功的方法
echo "xxxxxxxxx"|passwd --stdin user_name #这样设置密码就可以成功!
- Shell编程基础教程7--脚本参数的传递
7.脚本参数的传递 7.1.shift命令 简介: shift n 每次将参数位置向左偏移n位 例子 #!/bin/bash us ...
- Pyqt phonon的使用
本文是用Pyqt实现了下网上一个Qt版大牛关于phonon的介绍 Qt phonon地址:http://wenku.baidu.com/link?url=nH_dZ8lZbXHy8N5__8jAWLX ...
- 无废话ExtJs 入门教程十二[下拉列表联动:Combobox_Two]
无废话ExtJs 入门教程十二[下拉列表联动:Combobox_Two] extjs技术交流,欢迎加群(201926085) 不管是几级下拉列表的联动实现本质上都是根据某个下拉列表的变化,去动态加载其 ...
- maven pom.xml示例
示例说明: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3. ...
- 【leetcode】Reverse Integer
题目描述: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 很简单 ...
- C#中的Infinity有个小坑
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 昨天家里有事,上网也不方便,就没有推送文章.今天很累,也不长篇大论了.简单介绍一下最近遇到的 ...
- 即时通讯(IM-instant messager)
即时通讯又叫实时通讯,简单来说就是两个及以上的人使用网络进行文字.文件.语音和视频的交流. 首先,进行网络进行通信,肯定需要网络协议,即时通讯专用的协议就是xmpp.xmpp协议要传递的消息类型是xm ...
- 我的 Unity2D 屏幕适配
以下方法纯属我YY,切勿当真!!! 确定一个设计尺寸,比如 devWidth = 960,devHeight = 640, 按照这个尺寸进行设计游戏. 方式一: 不管什么屏幕尺寸,都和设计的尺寸对应. ...