昨晚上被叫去打cf,实在脑袋大,居然没有和他们撕逼。。。好吧,两天没睡觉还是能做出一题的。。。。
水题。
/*************************************************************************
> File Name: 1.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/25 星期一 下午 1:22:15
************************************************************************/
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int a1, a2, a3;
int b1, b2, b3;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("Out.txt", "w", stdout);
#endif
while(~sft(a1, a2, a3)) {
sft(b1, b2, b3);
sf(n);
int A = a1 + a2 + a3;
int B = b1 + b2 + b3;
n -= (A / 5 + (A % 5 == 0 ? 0 : 1));
n -= (B / 10 + (B % 10 == 0 ? 0 : 1));
if(n >= 0)
pfs("YES");
else
pfs("NO");
}
return 0;
}
这题的时候手速还算快。。不过接下来就各种懵逼了。。。
一看题目,尼玛后缀自动机和后缀数组还有树。。。我tm好像都不会的样子。。。
不过后来一看题目也ok。给你两个字符串,让你把第一个通过某种变换变成第二个,如果只要使用后缀自动机(删除字母),就输出。。。如果只要使用后缀数组(换位置),就输出。。。,如果都要用输出both,都不要就输出need tree。。。
好吧,今早上起来写完的。。昨天实在懵逼。。。
写得挺乱的。。直接贴了吧
/*************************************************************************
> File Name: 2.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/25 星期一 下午 1:40:31
************************************************************************/
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int index1, index2;
int len1, len2;
#define N 110
char str1[N];
char str2[N];
int coun[30];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("Out.txt", "w", stdout);
#endif
while(~sfs(str1)) {
sfs(str2);
index1 = false;
index2 = false;
len1 = strlen(str1);
len2 = strlen(str2);
index1 = (len1 == len2 ? false : true);
mem(coun, 0);
for(int i = 0; i < len1; i++) {
coun[str1[i] - 'a']++;
}
int j = 0;
for(j = 0; j < len2; j++) {
coun[str2[j] - 'a']--;
if(coun[str2[j] - 'a'] < 0) {
break;
}
}
if(j == len2) {
int i,k;
for(i = 0, k = 0; i < len1 && k < len2;) {
if(str1[i] == str2[k]) {
i++;k++;
}
else {
i++;
}
}
if(k != len2) {
index2 = true;
}
}
else {
index1 = false;
index2 = false;
}
if(index1 && index2) {
pfs("both");
}
else if(index1 && !index2) {
pfs("automaton");
}
else if(!index1 && index2) {
pfs("array");
}
else {
pfs("need tree");
}
//pfd(index1, index2);
}
return 0;
}
各种判断啦。
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted ann × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).
Print the k-th largest number in a n × m multiplication table.
2 2 2
2
2 3 4
3
1 10 5
5
A 2 × 3 multiplication table looks like this:
1 2 3 2 4 6
接下来第四题。第三题我还没看。。。n * m的乘法表,让你输出第k小的值。范围比较大没法存。千万注意用long long。
思想居然是二分。虽然我想到了(因为最小的肯定是1 * 1,最大的肯定是n * m),可是实在没法分啊。。(当时没想通,早上起来也没想通)。
易彰彪点化了我。。。这傻逼虽然晚上不睡觉但是做题还是挺可以。。
假如,我枚举一个数mid。那么是不是能算出比它小的数的个数和有多少个等于它的数?
既然能算出来,那是不是能判断这个数和k的大小?现在能不能二分?
的确有道理。。。。保存点啊什么的实在是没法做。。
二分我也写了好久。。途中错了好多次。。
贴代码吧。。
/*************************************************************************
> File Name: 4.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/26 星期二 上午 2:54:30
************************************************************************/
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
LL n, m, k;
LL counter(LL mid, int & md) {
int i = 1;
LL ans = 0;
while(i <= n && mid / i) {
if(i * m < mid) {
ans += m;
}
else {
ans += (mid / i);
if(mid % i == 0) {
md++;
}
}
i++;
}
return ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while(~scanf("%I64d%I64d%I64d", &n, &m, &k)) {
LL s = 1, e = n * m;
while(s <= e) {
LL mid = (s + e) >> 1;
int md = -1;
LL tmp = counter(mid, md);
if(k >= tmp - md && k <= tmp) {
pfI(mid);
break;
}
else if(k > tmp) {
s = mid + 1;
}
else if(k < tmp - md) {
e = mid - 1;
}
}
}
return 0;
}
另外两题再补上