360笔试 8.31 AC
1、子串
#include<iostream> #include<cstring> using namespace std; int main(){ string s; cin>>s; int map[256]; memset(map, 0, sizeof(map)); for(int i=0;i<s.length();i++){ map[s[i]]++; } int ans = 0; for(int i=0;i<256;i++){ if(map[i]>ans){ ans = map[i]; } } cout<<ans<<endl; return ans; }2、散步
#include<iostream> #include<cstring> #include<cstdlib> #define MAX_N 20005 using namespace std; int D[MAX_N]; int N, M; bool can_reach1(int x, int i){ if(x>N || x<1){ return false; }else if(i==M-1){ return true; } bool c1,c2; c1 = can_reach1(x-D[i], i+1); c2 = can_reach1(x+D[i], i+1); return c1 || c2; } int main(){ cin>>N>>M; memset(D, 0, sizeof(D)); for(int i=M-1;i>=0;i--){ int m;cin>>m; D[i] = m; } int ans = 0; for(int i=1;i<=N;i++){ if(can_reach1(i, 0)){ ans++; } } cout<<ans<<endl; return 0; }