@hsxrr
2016-12-13T20:01:11.000000Z
字数 1365
阅读 914
F - Linearization of the kernel functions in SVM
书写表达式
f(x,y,z) = ap + bq + cr + du + ev + fw + gx + hy + iz + j
有0,1,-1等特殊情况自行处理
满是坑坑的题目,特殊情况好多...
-1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 -1
等等..
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
int t;
char s[100] = {"pqruvwxyz\0"};
scanf("%d",&t);
bool first = true;
while( t-- ){
int l;
first = true;
for( int i = 0 ; i < 9 ; i++ ){
scanf("%d",&l);
if( l > 0 && !first){
if( l != 1 )
printf("+%d%c",l,s[i]);
else
printf("+%c",s[i]);
}else if( l < 0 || (first && l != 0) ){
first = false;
if( l != 1 && l != -1 )
printf("%d%c",l,s[i]);
else if( l == 1 )
printf("%c",s[i]);
else
printf("-%c",s[i]);
}
}
scanf("%d",&l);
if( l > 0 && !first )
printf("+");
if( l != 0 || first )
printf("%d",l);
printf("\n");
}
return 0;
}
找字符串中两个相同字符距离的最小值,没有相同的输出-1
记录出现字符过的最新位置,每次更新ans和字符位置即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int fcount[50],now[50],ans;
char s[1007];
void cc(){
memset(fcount,-1,sizeof(fcount));
memset(now,-1,sizeof(now));
ans = -1;
}
int main(){
int t,cas = 0,len;
scanf("%d",&t);
while(t--){
scanf("%s",s);
len = strlen(s);
cc();
for( int i = 0 ; i < len ; i++ ){
int f = s[i] - 'a';
if( now[f] == -1 ){
now[f] = i;
}else{
if( fcount[f] == -1 || fcount[f] > i - now[f] ){
fcount[f] = i - now[f];
}
now[f] = i;
if( fcount[f] != -1 && (ans == -1 || fcount[f] < ans ) ){
ans = fcount[f];
}
}
}
printf("Case #%d: %d\n",++cas,ans);
}
return 0;
}