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 ...
随机推荐
- iOS应用架构谈(二):View层的组织和调用方案(中)
iOS客户端应用架构看似简单,但实际上要考虑的事情不少.本文作者将以系列文章的形式来回答iOS应用架构中的种种问题,本文是其中的第二篇,主要讲View层的组织和调用方案.中篇主要讨论MVC.MVCS. ...
- CABasicAnimation animationWithKeyPath 一些规定的值
CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...
- python基础——返回函数
python基础——返回函数 函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回. 我们来实现一个可变参数的求和.通常情况下,求和的函数是这样定义的: def calc_ ...
- UVA 10192 Vacation
裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...
- iOS - 线程管理
iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...
- MVC学习笔记---各种上下文context
0 前言 AspNet MVC中比较重要的上下文,有如下: 核心的上下文有HttpContext(请求上下文),ControllerContext(控制器上下文) 过滤器有关有五个的上下文Actio ...
- 微信支付开发(1) JS API支付V3版(转)
http://www.cnblogs.com/txw1958/p/wxpayv3-jsapi.html 本文介绍微信支付下的jsapi实现流程 前言 微信支付现在分为v2版和v3版,2014年9月10 ...
- 【叉积】【sdut 2508 图形密码】
图形密码 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...
- SQLAlchemy ORM之建表与查询
作了最基本的操作,找找感觉.. #coding=utf-8 from datetime import datetime from sqlalchemy import (MetaData, Table, ...
- JavaScript - BOM
window 对象 window 对象是BOM的核心对象,也是ECMAScript规定的Global对象. 无法跨浏览精确获得窗口左边和上边的精确值,同样也无法确定浏览器窗口本身的大小,但是可以取得页 ...