A题 很简单,没什么好写的,直接上代码。
#include <stdio.h> #include <string.h> #include <cstdio> #include <math.h> #include <stdlib.h> int main() { int n; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d", &n); char s[1000]; scanf("%s", s); int len = strlen(s); int j = len/2; for(int i = 0; i < len/2; i++) { while(j<len) { if(s[i]!=s[j]) if(s[i]=='R'&&s[j]=='L') { printf("%d %d\n",j+1, i+1); j++; break; } printf("%d %d\n", i+1, j+1); j++; break; } } return 0; }
B题 #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #define eps 1e-5 #define MAXN 55555 #define MAXM 111111 #define INF 1000000007 #define lson (pos<<1) #define rson (pos<<1|1) using namespace std; struct node { int v;int No; }a[10000]; int cmp(node a, node b) { return a.v>b.v; } int main() { int n, k; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d%d", &n,&k); for(int i = 1; i <= n; i++) { scanf("%d", &a[i].v); a[i].No = i; } sort(a+1, a+1+n, cmp); int f[10000]; memset(f, 0, sizeof(f)); for(int i = 1; i <= k; i++) { f[a[i].No] = 1; } printf("%d\n", a[k].v); for(int i = 1; i <= n; i++) { if(f[i]) printf("%d ", i); } printf("\n"); return 0; }
C题 这个题我在每一个点都判断一下所需操作数 #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <map> using namespace std; int a[100010]; struct node { int da; int xiao; }b[100010]; int main() { int n; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); int up = 0, down = 0, zero=0; for(int i = 0; i < n; i++) { if(a[i]>0) up++; if(a[i]<0) down++; if(a[i]==0) zero++; b[i].da = up; b[i].xiao = down; // printf("i=%d up=%d down=%d zero=%d\n", i, up, down,zero); } int m = 0x7ffffff; for(int i = 0; i < n-1; i++) { int tmp = b[i].da+down-b[i].xiao; if(m>tmp) m = tmp; //printf("i=%d up=%d down=%d tmp=%d m=%d\n", i, b[i].da, b[i].xiao,tmp,m); } printf("%d\n", m+zero); return 0; }