content
stringlengths
19
11k
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int n; scanf("%d",&n); char tab[2*n][10]; for(int i=0;i<2*n;i++){ scanf("%s",&tab[i]); } int count=0; int i=0; while(i<n){ int j=n; while(j<2*n){ if(strcmp(tab[j],tab[i])==0){count++;tab[j][0]='Z';j=2*n;} j++; } i++; } printf("%d",n-count); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> int N; int check[201]; int main() { char a[201][10]; scanf("%d ", &N); for (int i = 1; i <= 2*N; i++) { gets(a[i]); } for (int i = 1; i <= N; i++) { for (int j = N + 1; j <= 2 * N; j++) { if (!strcmp(a[i], a[j]) && (check[i] == 0 && check[j] == 0)) { check[i] = 1; check[j] = 1; } } } int sum = 0; for (int i = 1; i <= N; i++) { if (check[i] == 0) { sum++; } } printf("%d", sum); }
/* Teng K. J. */ #include <stdio.h> #define N 3 #define M 4 int a[M][N]; int f(int ch) { switch (ch) { case 'S': return 0; case 'M': return 1; case 'L': return 2; }; return -1; } int main() { int n, ans = 0; int i, j, ch, t; scanf("%d", &n); getchar(); for (i = 0; i < n; i++) { t = 0; while ((ch = getchar()) == 'X') t++; a[t][f(ch)]++; getchar(); } for (i = 0; i < n; i++) { t = 0; while ((ch = getchar()) == 'X') t++; a[t][f(ch)]--; getchar(); } for (i = 0; i < M; i++) for (j = 0; j < N; j++) if (a[i][j] > 0) ans += a[i][j]; printf("%d", ans); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n; scanf("%d",&n); char a[n][100],b[n][100]; int strlen1[n],strlen2[n]; for(int i=0;i<n;i++) { scanf("%s",a[i]); strlen1[i]=strlen(a[i]); } for(int i=0;i<n;i++) { scanf("%s",b[i]); strlen2[i]=strlen(b[i]); } int f=0; int visited[100]; for(int i=0;i<100;i++) { visited[i]=0; } int count=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(strlen1[i]==strlen2[j] && visited[j]!=1) { if(strcmp(a[i],b[j])==0) { visited[j]=1; count++; break; } } } } printf("%d",n-count); }
#include<stdio.h> #include<math.h> int max3(int a1,int a2,int a3) { if(a1<a2) a1=a2; if(a1>a3) a3=a1; return a3; } int main() { int n; char c; int temp; int p[4]={0},q[4]={0},r[4]={0}; scanf("%d",&n); getchar(); for(int i=1;i<=n;i++){ temp=0; while((c=getchar())!='\n'){ if(c=='X') temp++; if(c=='L') p[temp]++; if(c=='M') q[temp]++; if(c=='S') r[temp]++; } } for(int i=1;i<=n;i++){ temp=0; while((c=getchar())!='\n'){ if(c=='X') temp++; if(c=='L') p[temp]--; if(c=='M') q[temp]--; if(c=='S') r[temp]--; } } int total=0; for(int i=0;i<=3;i++){ //SFD total+=max3(abs(p[i]),abs(q[i]),abs(r[i])); } printf("%d",total); return 0; }
#define _USE_MATH_DEFINES #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdbool.h> #include <float.h> #include <limits.h> #include <malloc.h> #include <memory.h> #include <complex.h> #include <errno.h> #include <time.h> int n,i,j,ans,f[105]={0},t; char *a[9]={"XXXS","XXS","XS","S","M","L","XL","XXL","XXXL"}; char s[105][105],ss[105][105]; int main() { scanf("%d\n",&n); for (i=1;i<=n;i++) { scanf("%s",s[i]); for (j=0;j<9;j++) if (strcmp(s[i],a[j])==0) { f[j]++; break; } } for (i=1,ans=0;i<=n;i++) { scanf("%s",ss[i]); for (j=0;j<9;j++) if (strcmp(ss[i],a[j])==0) { t=j; break; } if (f[t]) f[t]--; else ans++; } printf("%d\n",ans); return 0; }
#include <stdio.h> int get_index(char *string) { if (string[0] == 'S') return 0; if (string[0] == 'M') return 1; if (string[0] == 'L') return 2; if (string[1] == 'S') return 3; if (string[1] == 'L') return 4; if (string[2] == 'S') return 5; if (string[2] == 'L') return 6; if (string[3] == 'S') return 7; if (string[3] == 'L') return 8; return 0; } int main() { int cnt = 0; int n, i; int a[9] = {0}; int b[9] = {0}; char string[64]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", string); a[get_index(string)]++; } for (i = 0; i < n; i++) { scanf("%s", string); b[get_index(string)]++; } for (i = 0; i < 9; i++) { cnt += (a[i] > b[i]) ? (a[i] - b[i]) : (b[i] - a[i]); } printf("%d\n", cnt / 2); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int n; scanf("%d\n", &n); char stra[n][5]; char strb[n][5]; for (int i = 0; i < n; ++i) { scanf("%s", stra[i]); } for (int i = 0; i < n; ++i) { char temp[4]; scanf("%s", temp); int xx = 1; for (int j = 0; j < n; ++j) { if (strcmp(temp, stra[j])==0) { strcpy(stra[j], "a"); strcpy(strb[i], "a"); xx = 0; break; } } if (xx==1) { strcpy(strb[i], temp); } } // // // for (int i = 0; i < n; ++i) // { // printf("%s wasd\n", stra[i]); // }printf("\n"); // for (int i = 0; i < n; ++i) // { // printf("%s ffffffffffffff\n", strb[i]); // }printf("\n"); // // int count = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (strlen(stra[i])==strlen(strb[j]) && strcmp(stra[i], "a") && strcmp(strb[j], "a")) { count++; strcpy(strb[j], "a"); } } } printf("%d\n", count); return 0; }
#include <stdio.h> #include <string.h> int ones[3],OO[3], s[4], l[4], ans,n,i; int main(){char tmp[111]; for(scanf("%i", &n); i<n ; i++) { scanf("%s", tmp); int len = strlen(tmp); if(len==1){ if(tmp[0]=='M') ones[0]++; if(tmp[0]=='S') ones[1]++; if(tmp[0]=='L') ones[2]++; } else if(tmp[len-1]=='S') s[len-1]++; else if(tmp[len-1]=='L') l[len-1]++; } for(i=0;i<n;i++) { scanf("%s", tmp); int len = strlen(tmp); if(len==1){ if(tmp[0]=='M') OO[0]++; if(tmp[0]=='S') OO[1]++; if(tmp[0]=='L') OO[2]++; } else if(tmp[len-1]=='S') s[len-1]--; else if(tmp[len-1]=='L') l[len-1]--; } for(i=1 ; i<4 ; i++) if(s[i]<0) ans+= -s[i]; else if(l[i]<0) ans+= -l[i]; for(i=0 ; i<3 ; i++) if(ones[i]-OO[i]>0) ans+=ones[i]-OO[i]; printf("%i\n", ans); }
#include <stdio.h> #include <string.h> #define min(a, b) (a < b ? a : b) int last[9], cur[9]; char temp[10]; int N, i; void update(int test[9]) { for (i = 0; i < N; i++) { scanf("%s", temp); if (!strcmp(temp, "XXXS")) test[0]++; else if (!strcmp(temp, "XXS")) test[1]++; else if (!strcmp(temp, "XS")) test[2]++; else if (!strcmp(temp, "S")) test[3]++; else if (!strcmp(temp, "M")) test[4]++; else if (!strcmp(temp, "L")) test[5]++; else if (!strcmp(temp, "XL")) test[6]++; else if (!strcmp(temp, "XXL")) test[7]++; else test[8]++; } } int main() { int ans; memset(last, 0, sizeof(last)); memset(cur, 0, sizeof(cur)); scanf("%d", &N); update(last); update(cur); ans = N; for (i = 0; i < 9; i++) { if (cur[i] > 0 && last[i] > 0) { ans -= min(cur[i], last[i]); } } printf("%d\n", ans); return 0; }
#include <stdio.h> #include <stdlib.h> #define NUMBER_OF_SIZES 9 void scanfSizes(int sizes[ NUMBER_OF_SIZES ], int sizesLength) { char word[ 5 ]; int i, j; for ( i = 0; i < sizesLength; i++ ) { scanf( "" ); scanf( " %s", word ); if ( word[ 0 ] == 'M' ) { sizes[ NUMBER_OF_SIZES - 1 ]++; } else { int letterPosition = 0; while ( word[ letterPosition ] == 'X' ) { letterPosition++; } switch ( word[ letterPosition ] ) { case 'S': sizes[ 2 * letterPosition ]++; break; case 'L': sizes[ 2 * letterPosition + 1 ]++; break; } } } } int main() { int n; scanf( "%d", &n ); int i; int lastYearSizes[ NUMBER_OF_SIZES ]; for ( i = 0; i < NUMBER_OF_SIZES; i++ ) { lastYearSizes[ i ] = 0; } scanfSizes( lastYearSizes, n ); int currentYearSizes[ NUMBER_OF_SIZES ]; for ( i = 0; i < NUMBER_OF_SIZES; i++ ) { currentYearSizes[ i ] = 0; } scanfSizes( currentYearSizes, n ); int seconds = 0; for ( i = 0; i < NUMBER_OF_SIZES; i++ ) { seconds += abs( lastYearSizes[ i ] - currentYearSizes[ i ] ); } printf( "%d", seconds / 2 ); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> long int a[10]={0}; //XXXS,XXS,XS,S,M,L,XL,XXL,XXXL long int b[10]={0}; char s[100]; int main(){ long int i,j,k,l,t,n,x,y,count,flag,m; scanf("%ld",&n); for(i=0;i<n;i++) { scanf("%s",s); j = strlen(s); if(j==1){ if(s[0]=='S') a[3]++; else if(s[0]=='M') a[4]++; else if(s[0]=='L') a[5]++; } else if(j==2){ if(s[1]=='S') a[2]++; else if(s[1]=='L') a[6]++; } else if(j==3){ if(s[2]=='S') a[1]++; else if(s[2]=='L') a[7]++; } else if(j==4){ if(s[3]=='S') a[0]++; else if(s[3]=='L') a[8]++; } } for(i=0;i<n;i++) { scanf("%s",s); j = strlen(s); if(j==1){ if(s[0]=='S') b[3]++; else if(s[0]=='M') b[4]++; else if(s[0]=='L') b[5]++; } else if(j==2){ if(s[1]=='S') b[2]++; else if(s[1]=='L') b[6]++; } else if(j==3){ if(s[2]=='S') b[1]++; else if(s[2]=='L') b[7]++; } else if(j==4){ if(s[3]=='S') b[0]++; else if(s[3]=='L') b[8]++; } } count= 0; for(i=0;i<=8;i++){ //hprintf("%ld %ld\n",a[i],b[i]); count += abs(a[i]-b[i]); } printf("%ld\n",count/2); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int i, j, k, l, count, c_count, d, nm= 0, n; scanf("%i", &n); char *size_pre[n], *size_cur[n]; for(i=0; i<n; ++i){ size_pre[i]= malloc(10); scanf("%s", size_pre[i]); } for(i=0; i<n; ++i){ size_cur[i]= malloc(10); scanf("%s", size_cur[i]); } for(i=0; i<n; ++i){ c_count= 0; for(j=0; j<n; ++j){ if(strlen(size_cur[i])== strlen(size_pre[j])){ count= strlen(size_cur[i]); for(k=0, l=0; size_cur[i][k]!= '\0'; ++k, ++l){ if(size_cur[i][k]==size_pre[j][l]){ --count; } } if(!count){ c_count= 1; d= j; } } } if(c_count){ size_pre[d]= "z"; ++nm; } } printf("%i", n-nm); for(i=0; i<n; ++i){ free(size_pre[i]); free(size_cur[i]); } }
#include <stdio.h> #include <string.h> #define MAX_COUNT 100 #define MAX_LEN 6 #define INFINITE 100000 void ReadLine(char *str, int size) { fgets(str, size, stdin); if (str[strlen(str) - 1] == '\n') { str[strlen(str) - 1] = '\0'; } } int GetDiff(char *str1, char *str2) { if (*str1 == '\0' || *str2 == '\0') { return INFINITE; } int diff = 0; while ((*str1 != '\0') && (*str2 != '\0')) { diff += (*str1 != *str2) ? 1 : 0; str1 += 1; str2 += 1; } return (*str1 != '\0' || *str2 != '\0') ? INFINITE : diff; } int main() { int count; scanf("%d%*c", &count); char last[MAX_COUNT][MAX_LEN]; char curr[MAX_COUNT][MAX_LEN]; int i; for (i = 0; i < count; ++i) { ReadLine(last[i], MAX_LEN); } for (i = 0; i < count; ++i) { ReadLine(curr[i], MAX_LEN); } int changes = 0; for (i = 0; i < count; ++i) { int min_diff = MAX_LEN; int best_j = -1; int best_k = -1; int j, k; for (j = 0; j < count; ++j) { for (k = 0; k < count; ++k) { int diff = GetDiff(last[j], curr[k]); if (diff < min_diff) { min_diff = diff; best_j = j; best_k = k; } } } changes += min_diff; last[best_j][0] = '\0'; curr[best_k][0] = '\0'; } printf("%d\n", changes); return 0; }
#include<stdio.h> #include<string.h> int main() { int n,result=0,i; int last[15]={0}; scanf("%d",&n); getchar(); char s[10]; for(i=0;i<n;i++){ gets(s); int l=strlen(s); switch(l){ case 1: if(s[0]=='S') last[4]++; if(s[0]=='M') last[5]++; if(s[0]=='L') last[6]++; break; case 2: if(s[l-1]=='S') last[3]++; if(s[l-1]=='L') last[7]++; break; case 3: if(s[l-1]=='S') last[2]++; if(s[l-1]=='L') last[8]++; break; case 4: if(s[l-1]=='S') last[1]++; if(s[l-1]=='L') last[9]++; break; } } int j=0; int now[103]={0}; int p=0; int alone[101]={0}; for(i=0;i<n;i++){ gets(s); int l=strlen(s); switch(l){ case 1: if(s[0]=='S') alone[p++]=4; if(s[0]=='M') alone[p++]=5; if(s[0]=='L') alone[p++]=6; break; case 2: if(s[l-1]=='S') now[j++]=3; if(s[l-1]=='L') now[j++]=7; break; case 3: if(s[l-1]=='S') now[j++]=2; if(s[l-1]=='L') now[j++]=8; break; case 4: if(s[l-1]=='S') now[j++]=1; if(s[l-1]=='L') now[j++]=9; break; } } for(i=0;i<j;i++){ if(last[now[i]]<=0){ // no exist last[10-now[i]]--; result++; }else{ last[now[i]]--; } } int t=p; for(i=0;i<p;i++){ if(last[alone[i]]>0){ last[alone[i]]--; alone[i]=-1; t--; } } printf("%d",result+t); }
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 20 void heapSort(char strings[][MAX], int n); void heapify(char strings[][MAX], int esq, int dir); void buildHeap(char strings[][MAX], int n); int main(){ int n, i; scanf("%d", &n); char LY[n][MAX]; char CY[n][MAX]; for(i=0;i<n;i++){ scanf("\n%s", LY[i]); } for(i=0;i<n;i++){ scanf("\n%s", CY[i]); } //heapSort(LY, n); //heapSort(CY, n); int eq=0, j; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(strcmp(CY[i], LY[j]) == 0){ eq++; strcpy(LY[j], "aaaaa"); break; } } } printf("%d\n", n-eq); return 0; } void heapSort(char strings[][MAX], int n){ int esq = 0; int dir = n-1; buildHeap(strings, n); while(dir > 0){ char tmp[MAX]; strcpy(tmp, strings[dir]); strcpy(strings[dir], strings[0]); strcpy(strings[0], tmp); dir--; heapify(strings, esq, dir); } } void heapify(char strings[][MAX], int esq, int dir){ int i = esq; int j = (i*2)+1; char x[MAX]; strcpy(x, strings[i]); while(j<=dir){ if(j < dir){ if(strcmp(strings[j], strings[j+1]) < 0){ j++; } } if(strcmp(x, strings[j]) >= 0){ break; } strcpy(strings[i], strings[j]); i = j; j = (2*i)+1; } strcpy(strings[i], x); } void buildHeap(char strings[][MAX], int n){ int esq = n/2 + 1; while(esq>0){ esq--; heapify(strings, esq, n-1); } }
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n; int i[3][10]; int a,res = 0,mo = 0,le = 0; memset(i,0,sizeof(i)); scanf("%d",&n); for(a = 1;a <= n;a ++) { char st1[20]; scanf("%s",&st1); if(st1[0] == 'M') { i[1][1] ++; } else if(st1[0] == 'S') { i[1][2] ++; } else if(st1[0] == 'L') { i[1][3] ++; } else if(st1[1] == 'S') { i[1][4] ++; } else if(st1[1] == 'L') { i[1][5] ++; } else if(st1[2] == 'S') { i[1][6] ++; } else if(st1[2] == 'L') { i[1][7] ++; } else if(st1[3] == 'S') { i[1][8] ++; } else if(st1[3] == 'L') { i[1][9] ++; } } for(a = 1;a <= n;a ++) { char st2[20]; scanf("%s",&st2); if(st2[0] == 'M') { i[2][1] ++; } else if(st2[0] == 'S') { i[2][2] ++; } else if(st2[0] == 'L') { i[2][3] ++; } else if(st2[1] == 'S') { i[2][4] ++; } else if(st2[1] == 'L') { i[2][5] ++; } else if(st2[2] == 'S') { i[2][6] ++; } else if(st2[2] == 'L') { i[2][7] ++; } else if(st2[3] == 'S') { i[2][8] ++; } else if(st2[3] == 'L') { i[2][9] ++; } } for(a = 1;a <= 3;a ++) if(i[2][a] < i[1][a]) { res += (i[1][a] - i[2][a]); } for(a = 5;a <= 9;a += 2) { res += (abs(i[1][a] - i[2][a])); } printf("%d",res); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n, a[9] = {}, b[9] = {}, i, o; char in[5]; scanf("%d", &o); n = o; while (n--) { scanf("%s", in); if (strlen(in) == 4) if (in[3] == 'S') a[8]++; else a[0]++; else if (strlen(in) == 3) if (in[2] == 'S') a[7]++; else a[1]++; else if (strlen(in) == 2) if (in[1] == 'S') a[6]++; else a[2]++; else if (in[0] == 'S') a[5]++; else if (in[0] == 'M') a[4]++; else a[3]++; } n = o; while (n--) { scanf("%s", in); if (strlen(in) == 4) if (in[3] == 'S') b[8]++; else b[0]++; else if (strlen(in) == 3) if (in[2] == 'S') b[7]++; else b[1]++; else if (strlen(in) == 2) if (in[1] == 'S') b[6]++; else b[2]++; else if (in[0] == 'S') b[5]++; else if (in[0] == 'M') b[4]++; else b[3]++; } int sum = 0; for (i = 0; i < 9; i++) sum += abs(a[i] - b[i]); printf("%d\n", sum / 2); }
#include <stdio.h> #include <string.h> int small_previous[4]; /* S occurences for 0 - 3 X (S, XS, XXS, XXXS) */ int large_previous[4]; /* L occurences for 0 - 3 X (L, XL, XXL, XXXL) */ int small_current[4]; /* S occurences for 0 - 3 X (S, XS, XXS, XXXS) */ int large_current[4]; /* L occurences for 0 - 3 X (L, XL, XXL, XXXL) */ int medium_previous; int medium_current; int n; int main() { int i, result; char aux[10]; scanf("%d\n", &n); /* -- PREVIOUS YEAR -- */ for (i = 0; i < n; i++) { scanf("%s\n", aux); if (aux[0] == 'M') medium_previous++; else if (aux[strlen(aux) - 1] == 'S') small_previous[strlen(aux) - 1]++; else large_previous[strlen(aux) - 1]++; } /* -- CURRENT YEAR -- */ for (i = 0; i < n; i++) { scanf("%s\n", aux); if (aux[0] == 'M') medium_current++; else if (aux[strlen(aux) - 1] == 'S') small_current[strlen(aux) - 1]++; else large_current[strlen(aux) - 1]++; } result = 0; for (i = 0; i < 4; i++) { if (small_previous[i] < small_current[i]) result += small_current[i] - small_previous[i]; if (large_previous[i] < large_current[i]) result += large_current[i] - large_previous[i]; } if (medium_previous < medium_current) result += medium_current - medium_previous; printf("%d\n", result); return 0; }
#include<stdio.h> #include<string.h> #include<stdlib.h> int strp[102],strn[102]; int main () { int i,n; char str[6],m[]="M",l[]="L",s[]="S",xs[]="XS",xl[]="XL",xxs[]="XXS",xxl[]="XXL",xxxs[]="XXXS",xxxl[]="XXXL"; scanf ("%d",&n); for (i = 0; i < n ; i++) { scanf(" %[^\n]",str); if (strcmp(str,l)== 0) strp[1]++; else if (strcmp(str,m)== 0) strp[2]++; else if (strcmp(str,s)== 0 ) strp[3]++; else if (strcmp (str,xs)==0) strp[4]++; else if (strcmp(str,xl)== 0) strp[5]++; else if (strcmp(str,xxs)==0) strp[6]++; else if (strcmp (str,xxl)== 0) strp[7]++; else if (strcmp (str,xxxs)==0) strp[8]++; else if (strcmp(str,xxxl)== 0) strp[9]++; } for (i = 0; i < n ; i++) { scanf(" %[^\n]",str); if (strcmp(str,l)== 0) strn[1]++; else if (strcmp(str,m)== 0) strn[2]++; else if (strcmp(str,s)== 0 ) strn[3]++; else if (strcmp (str,xs)==0) strn[4]++; else if (strcmp(str,xl)== 0) strn[5]++; else if (strcmp(str,xxs)==0) strn[6]++; else if (strcmp (str,xxl)== 0) strn[7]++; else if (strcmp (str,xxxs)==0) strn[8]++; else if (strcmp(str,xxxl)== 0) strn[9]++; } int sum = 0; for (i = 0 ; i <10 ; i++) { if (strn[i] > strp[i]) { sum = sum + strn[i]-strp[i]; } } printf ("%d\n",sum); return 0; }
#include <stdio.h> #include <stdlib.h> int main() { int i=0,j=0,m,n,x=0,num_a_s=0,num_a_m=0,num_a_i=0,c[5][10],sum=0,count=0,s1,m1,l1; char a[500],b[500]; memset(c, 0, sizeof(c)); scanf("%d",&n); getchar(); for(i=0,m=0;m<n;i++){ scanf("%c",&a[i]); if(a[i]=='\n'){ m++; i--; } } for(i=0,m=0;m<n;i++){ scanf("%c",&b[i]); if(b[i]=='\n'){ m++; i--; } } for(j=0;j<i;j++){ if(a[j]=='S'){ c[x][1]++; x=0; } else if(a[j]=='M'){ c[x][2]++; x=0; } else if(a[j]=='L'){ c[x][3]++; x=0; } else x++; } for(j=0;j<i;j++){ if(b[j]=='S'){ c[x][4]++; x=0; } else if(b[j]=='M'){ c[x][5]++; x=0; } else if(b[j]=='L'){ c[x][6]++; x=0; } else x++; } for(i=0;i<=3;i++){ if(i==0){ s1=c[i][1]-c[i][4]; s1=abs(s1); m1=c[i][2]-c[i][5]; m1=abs(m1); l1=c[i][3]-c[i][6]; l1=abs(l1); if(s1>=m1){ if(l1>=s1) count=l1; else count=s1; } else if(m1>=s1){ if(l1>=m1) count=l1; else count=m1; } } else if(c[i][1]>c[i][4]) count=c[i][1]-c[i][4]; else count=c[i][4]-c[i][1]; sum+=count; } printf("%d", sum); return 0; }
#include <stdio.h> int main(void) { int n , asizes[9] = {0,0,0,0,0,0,0,0,0} , bsizes[9] = {0,0,0,0,0,0,0,0,0} , answer, temp; scanf("%d",&n); char a[n][5], b[n][5]; for (int i =0; i < n ; i++ ) { scanf("%s",a[i]); if(a[i][3] == 'S') asizes[0]++ ; else if(a[i][2] == 'S') asizes[1]++ ; else if(a[i][1] == 'S') asizes[2]++ ; else if(a[i][0] == 'S') asizes[3]++ ; else if(a[i][0] == 'M') asizes[4]++ ; else if(a[i][0] == 'L') asizes[5]++ ; else if(a[i][1] == 'L') asizes[6]++ ; else if(a[i][2] == 'L') asizes[7]++ ; else if(a[i][3] == 'L') asizes[8]++ ; else return 0; } for (int i =0; i < n ; i++ ) { scanf("%s",b[i]); if(b[i][3] == 'S') bsizes[0]++ ; else if(b[i][2] == 'S') bsizes[1]++ ; else if(b[i][1] == 'S') bsizes[2]++ ; else if(b[i][0] == 'S') bsizes[3]++ ; else if(b[i][0] == 'M') bsizes[4]++ ; else if(b[i][0] == 'L') bsizes[5]++ ; else if(b[i][1] == 'L') bsizes[6]++ ; else if(b[i][2] == 'L') bsizes[7]++ ; else if(b[i][3] == 'L') bsizes[8]++ ; else return 0; } for(int i = 3 ; i < 6 ; i++ ){ temp = (temp = asizes[i] - bsizes[i]) > 0 ? temp : -temp; answer = answer + temp ; temp =0; } answer = answer / 2 ; for(int i = 0; i < 3 ; i++ ){ temp = ((temp = asizes[i]-bsizes[i]) > 0) ? temp: (-temp); answer = answer + temp ; temp =0; } printf(" %d",answer); return 0; }
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,l,temp,step,c=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,c10=0,c11=0,c12=0,c13=0,c14=0,c15=0,c16=0,c17=0,c18=0; scanf("%d",&n); int a[n],b[n],i,j,p=0,fre[100]; char t[100]; char s1[200][4],s2[200][4],s3[10][10]={"S","M","XL","XS","XXL","XXS","XXXL","XXXS","L"}; for(i=0;i<n;i++) { scanf("%s",s1[i]); a[i]=strlen(s1[i]); if(strcmp(s1[i],s3[0])==0) { c1++; } else if(strcmp(s1[i],s3[1])==0) { c2++; } else if(strcmp(s1[i],s3[2])==0) { c3++; } else if(strcmp(s1[i],s3[3])==0) { c4++; } else if(strcmp(s1[i],s3[4])==0) { c5++; } else if(strcmp(s1[i],s3[5])==0) { c6++; } else if(strcmp(s1[i],s3[6])==0) { c7++; } else if(strcmp(s1[i],s3[7])==0) { c8++; } else if(strcmp(s1[i],s3[8])==0) { c17++; } } for(i=0;i<n;i++) { scanf("%s",s2[i]); b[i]=strlen(s2[i]); if(strcmp(s2[i],s3[0])==0) { c9++; } else if(strcmp(s2[i],s3[1])==0) { c10++; } else if(strcmp(s2[i],s3[2])==0) { c11++; } else if(strcmp(s2[i],s3[3])==0) { c12++; } else if(strcmp(s2[i],s3[4])==0) { c13++; } else if(strcmp(s2[i],s3[5])==0) { c14++; } else if(strcmp(s2[i],s3[6])==0) { c15++; } else if(strcmp(s2[i],s3[7])==0) { c16++; } else if(strcmp(s2[i],s3[8])==0) { c18++; } } if(c9>c1) { c+=(c9-c1); } if(c10>c2) { c+=(c10-c2); } if(c11>c3) { c+=(c11-c3); } if(c12>c4) { c+=(c12-c4); } if(c13>c5) { c+=(c13-c5); } if(c14>c6) { c+=(c14-c6); } if(c15>c7) { c+=(c15-c7); } if(c16>c8) { c+=(c16-c8); } if(c18>c17) { c+=(c18-c17); } printf("%d\n",c); return 0; }
#include <string.h> #include <stdlib.h> #include <stdio.h> #define SIZE_S 0 #define SIZE_XS 1 #define SIZE_XXS 2 #define SIZE_XXXS 3 #define SIZE_M 4 #define SIZE_L 5 #define SIZE_XL 6 #define SIZE_XXL 7 #define SIZE_XXXL 8 #define SIZE_MAX 9 #define GET_ARRAY(size) SIZE_##size static int previous[SIZE_MAX] = {0}; static int current[SIZE_MAX] = {0}; int main() { int total_num; scanf("%d", &total_num); int i; char prev[10] = {0}; char curr[10] = {0}; for (i = 0; i < total_num; i ++) { scanf("%s", prev); if (strcmp(prev, "S") == 0) previous[GET_ARRAY(S)] ++; if (strcmp(prev, "XS") == 0) previous[GET_ARRAY(XS)] ++; if (strcmp(prev, "XXS") == 0) previous[GET_ARRAY(XXS)] ++; if (strcmp(prev, "XXXS") == 0) previous[GET_ARRAY(XXXS)] ++; if (strcmp(prev, "M") == 0) previous[GET_ARRAY(M)] ++; if (strcmp(prev, "L") == 0) previous[GET_ARRAY(L)] ++; if (strcmp(prev, "XL") == 0) previous[GET_ARRAY(XL)] ++; if (strcmp(prev, "XXL") == 0) previous[GET_ARRAY(XXL)] ++; if (strcmp(prev, "XXXL") == 0) previous[GET_ARRAY(XXXL)] ++; } for (i = 0; i < total_num; i ++) { scanf("%s", curr); if (strcmp(curr, "S") == 0) current[GET_ARRAY(S)] ++; if (strcmp(curr, "XS") == 0) current[GET_ARRAY(XS)] ++; if (strcmp(curr, "XXS") == 0) current[GET_ARRAY(XXS)] ++; if (strcmp(curr, "XXXS") == 0) current[GET_ARRAY(XXXS)] ++; if (strcmp(curr, "M") == 0) current[GET_ARRAY(M)] ++; if (strcmp(curr, "L") == 0) current[GET_ARRAY(L)] ++; if (strcmp(curr, "XL") == 0) current[GET_ARRAY(XL)] ++; if (strcmp(curr, "XXL") == 0) current[GET_ARRAY(XXL)] ++; if (strcmp(curr, "XXXL") == 0) current[GET_ARRAY(XXXL)] ++; } int result = 0; for (i = 0; i < SIZE_MAX; i ++) { result += (current[i] - previous[i]) > 0 ? (current[i] - previous[i]) : 0; } printf("%d", result); }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n,i,ans,M = 0,S = 0,L = 0,XS = 0,XXS = 0,XXXS = 0,XL = 0,XXL = 0,XXXL = 0,M2 = 0,S2 = 0,L2 = 0,XS2 = 0,XXS2 = 0,XXXS2 = 0,XL2 = 0,XXL2 = 0,XXXL2 = 0; scanf("%d",&n); char Tshirts[n][100],Tshirts2[n][100]; for (i = 0; i < n; i++) { scanf("%s", Tshirts[i]); } for (i = 0; i < n; i++) { scanf("%s", Tshirts2[i]); } for (i = 0; i < n; i++) { if (strcmp(Tshirts[i],"M") == 0) M++; else if (strcmp(Tshirts[i],"S") == 0) S++; else if (strcmp(Tshirts[i],"L") == 0) L++; else if (strcmp(Tshirts[i],"XS") == 0) XS++; else if (strcmp(Tshirts[i],"XL") == 0) XL++; else if (strcmp(Tshirts[i],"XXS") == 0) XXS++; else if (strcmp(Tshirts[i],"XXL") == 0) XXL++; else if (strcmp(Tshirts[i],"XXXS") == 0) XXXS++; else if (strcmp(Tshirts[i],"XXXL") == 0) XXXL++; } for (i = 0; i < n; i++) { if (strcmp(Tshirts2[i],"M") == 0) M2++; else if (strcmp(Tshirts2[i],"S") == 0) S2++; else if (strcmp(Tshirts2[i],"L") == 0) L2++; else if (strcmp(Tshirts2[i],"XS") == 0) XS2++; else if (strcmp(Tshirts2[i],"XL") == 0) XL2++; else if (strcmp(Tshirts2[i],"XXS") == 0) XXS2++; else if (strcmp(Tshirts2[i],"XXL") == 0) XXL2++; else if (strcmp(Tshirts2[i],"XXXS") == 0) XXXS2++; else if (strcmp(Tshirts2[i],"XXXL") == 0) XXXL2++; } if ((M == M2) && (S == S2) && (L == L2) && (XS == XS2) && (XXS == XXS2) && (XXXS == XXXS2) && (XL == XL2) && (XXL == XXL2) && (XXXL == XXXL2) ) ans = 0; else ans = (abs(M2-M) + abs(S2-S) + abs(L2-L) + abs(XS2-XS) + abs(XXS2-XXS) + abs(XXXS2-XXXS) + abs(XL2-XL) + abs(XXL2-XXL) + abs(XXXL2-XXXL))/2; printf("%d",ans); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int n; scanf ("%d", &n); int ans = 0; int cnt[9] = {0}; for (int i = 0; i < n; i++) { char name[5]; scanf ("%s", name); if (!strcmp("XXXS", name)) cnt[0]++; else if (!strcmp("XXS", name)) cnt[1]++; else if (!strcmp("XS", name)) cnt[2]++; else if (!strcmp("S", name)) cnt[3]++; else if (!strcmp("M", name)) cnt[4]++; else if (!strcmp("L", name)) cnt[5]++; else if (!strcmp("XL", name)) cnt[6]++; else if (!strcmp("XXL", name)) cnt[7]++; else if (!strcmp("XXXL", name)) cnt[8]++; } for (int i = 0; i < n; i++) { char name[5]; scanf ("%s", name); if (!strcmp("XXXS", name)) { if (cnt[0]) cnt[0]--; else ans++; } else if (!strcmp("XXS", name)){ if (cnt[1]) cnt[1]--; else ans++; } else if (!strcmp("XS", name)){ if (cnt[2]) cnt[2]--; else ans++; } else if (!strcmp("S", name)){ if (cnt[3]) cnt[3]--; else ans++; } else if (!strcmp("M", name)){ if (cnt[4]) cnt[4]--; else ans++; } else if (!strcmp("L", name)){ if (cnt[5]) cnt[5]--; else ans++; } else if (!strcmp("XL", name)){ if (cnt[6]) cnt[6]--; else ans++; } else if (!strcmp("XXL", name)){ if (cnt[7]) cnt[7]--; else ans++; } else if (!strcmp("XXXL", name)){ if (cnt[8]) cnt[8]--; else ans++; } } printf ("%d", ans); return 0; }
#include <stdio.h> #include <string.h> int main () { long long int a, b, c, d, i, j, k, l, ln, ln1, sum = 0, sum1, ck = 0, ck1, ct = 0, ct1, p, q, m, n, max, max1, min, min1, start, end, mid; long long int a1 = 0, a2 = 0, a3 = 0, a4 = 0; float x, y, z; char ch, ch1; char s[200][200], s1[200][200], s2[2000]; long long int arr[2000], arr1[2000], arr2[2000]; scanf("%lld", &n); for(i = 0; i < n; i++) { scanf("%s", s[i]); } for(i = 0; i < n; i++) { scanf("%s", s1[i]); } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { ck = 0; for(k = 0; k < a2; k++) { if(arr1[k] == j) { ck = 1; break; } } if(ck == 0) { if(strcmp(s[i], s1[j]) == 0) { arr[a1] = i; a1++; arr1[a2] = j; a2++; break; } } } } if(a1 == n) { printf("0\n"); return 0; } for(i = 0; i < n; i++) { if(a1 == n) { printf("%lld\n", ct); return 0; } ck = 0; for(j = 0; j < a1; j++) { if(arr[j] == i) { ck = 1; break; } } if(ck == 0) { ln = strlen(s[i]); for(k = 0; k < n; k++) { ck = 0; for(j = 0; j < a1; j++) { if(arr1[j] == k) { ck = 1; break; } } if(ck == 0) { ln1 = strlen(s1[k]); if(ln == ln1) { ct++; arr[a1] = i; a1++; arr1[a2] = k; a2++; } } } } } printf("%lld\n", ct); return 0; }
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,l,temp,step,c=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,c10=0,c11=0,c12=0,c13=0,c14=0,c15=0,c16=0,c17=0,c18=0; scanf("%d",&n); int a[n],b[n],i,j,p=0,fre[100]; char t[100]; char s1[200][4],s2[200][4],s3[10][10]={"S","M","XL","XS","XXL","XXS","XXXL","XXXS","L"}; /* for(i=0;i<=5000;i++) { fre[i]=0; }*/ for(i=0;i<n;i++) { scanf("%s",s1[i]); a[i]=strlen(s1[i]); if(strcmp(s1[i],s3[0])==0) { c1++; } else if(strcmp(s1[i],s3[1])==0) { c2++; } else if(strcmp(s1[i],s3[2])==0) { c3++; } else if(strcmp(s1[i],s3[3])==0) { c4++; } else if(strcmp(s1[i],s3[4])==0) { c5++; } else if(strcmp(s1[i],s3[5])==0) { c6++; } else if(strcmp(s1[i],s3[6])==0) { c7++; } else if(strcmp(s1[i],s3[7])==0) { c8++; } else if(strcmp(s1[i],s3[8])==0) { c17++; } } for(i=0;i<n;i++) { scanf("%s",s2[i]); b[i]=strlen(s2[i]); if(strcmp(s2[i],s3[0])==0) { c9++; } else if(strcmp(s2[i],s3[1])==0) { c10++; } else if(strcmp(s2[i],s3[2])==0) { c11++; } else if(strcmp(s2[i],s3[3])==0) { c12++; } else if(strcmp(s2[i],s3[4])==0) { c13++; } else if(strcmp(s2[i],s3[5])==0) { c14++; } else if(strcmp(s2[i],s3[6])==0) { c15++; } else if(strcmp(s2[i],s3[7])==0) { c16++; } else if(strcmp(s2[i],s3[8])==0) { c18++; } } if(c9>c1) { c+=(c9-c1); } if(c10>c2) { c+=(c10-c2); } if(c11>c3) { c+=(c11-c3); } if(c12>c4) { c+=(c12-c4); } if(c13>c5) { c+=(c13-c5); } if(c14>c6) { c+=(c14-c6); } if(c15>c7) { c+=(c15-c7); } if(c16>c8) { c+=(c16-c8); } if(c18>c17) { c+=(c18-c17); } /* for(i=0;i<n;i++) { int flag=0; for(j=0;j<n;j++) { if(strcmp(s2[i],s1[j])==0) { flag=1; fre[j]++; break; } } if(flag==1) { c++; } } for(i=0;i<=n;i++) { if(fre[i]>1) { c-=fre[i]-1; } } for(step=1;step<n;step++) { for(i=0;i<n-step;i++) { if(strcmp(s1[i],s1[i+1])>0) { strcpy(t,s1[i]); strcpy(s1[i],s1[i+1]); strcpy(s1[i+1],t); } } } for(step=1;step<n;step++) { for(i=0;i<n-step;i++) { if(strcmp(s2[i],s2[i+1])>0) { strcpy(t,s2[i]); strcpy(s2[i],s2[i+1]); strcpy(s2[i+1],t); } } }*/ /* for(i=0;i<n;i++) { int flag=0; for(j=p;j<n;j++) { if(strcmp(s2[i],s1[j])!=0 && b[i]==a[j]) { p=j+1; c++; break; } } }*/ /* for(i=0;i<n;i++) { printf("%s\n",s1[i]); } for(i=0;i<n;i++) { printf("%s\n",s2[i]); } for(i=0;i<n;i++) { if(strcmp(s1[i],s2[i])!=0) { c++; } }*/ /* printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16);*/ printf("%d\n",c); return 0; }
#include <stdio.h> #define MAX 200200 #define Max(a,b) (a>b?a:b) long long n,m,z,i,a[MAX],f[MAX], b[MAX],*A=a+2,*B=b+2,*F=f+2; int main(){ for(scanf("%I64d%I64d",&n,&m),i=1;i<=n;i++) scanf("%I64d", &A[i]); for(A[i]=m,n+=2,i=n-2;i>=0;i--) B[i]=A[i+1]-A[i]+B[i+2]; for(z=B[0], i=0;i<n-1;i++){ F[i]=A[i+1]-A[i]+F[i-2]; if(i%2) z=Max(B[i]-1+F[i-1], z); else z=Max(F[i]-1+B[i+1], z); } printf("%I64d\n", z); }
#include<stdio.h> int a[100007],n,m; int dp[100007]; void run(){ int i,x,r; while(scanf("%d%d",&n,&m)!=EOF){ for(i=0;i<n;i++){ scanf("%d",&a[i]); } a[n]=m; dp[0]=a[0]; for(i=1;i<=n;i++){ if(i%2==1){ dp[i]=dp[i-1]; continue; } dp[i]=dp[i-1]+a[i]-a[i-1]; } r=dp[n]; for(i=0;i<n;i++){ if(i%2==1){ continue; } if(a[i]-(i-1>=0?a[i-1]:0)>1){ x=dp[i]-1; x+=m-a[i]-(dp[n]-dp[i]); if(r<x){ r=x; } } if(a[i+1]-a[i]>1){ x=dp[i]-1; x+=m-a[i]-(dp[n]-dp[i]); if(r<x){ r=x; } } } printf("%d\n",r); } } main(){ #ifndef ONLINE_JUDGE freopen("e45b_min.in","rb",stdin); freopen("e45b_.out","wb",stdout); #endif run(); return 0; }
/* Teng K. J. */ #include <stdio.h> #define N 100000 #define M(x,y) ((x)>(y)?(x):(y)) int a[N + 2]; int on[N + 2], off[N + 2]; int main() { int n, m, ans = 0; int i; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &a[i + 1]); } if (!(n & 1)) { a[++n] = m; } off[n] = m - a[n]; for (i = n - 1; i >= 0; i--) { if (i & 1) { off[i] = off[i + 1] + a[i + 1] - a[i]; on[i] = on[i + 1]; } else { on[i] = on[i + 1] + a[i + 1] - a[i]; off[i] = off[i + 1]; } } ans = on[0]; for (i = 1; i < n; i += 2) { if (a[i] - a[i - 1] != 1 || a[i + 1] - a[i] != 1) { int newon = off[i] + on[0] - on[i] - 1; if (newon > ans) ans = newon; } } if (a[n] != m && (a[n] != m - 1 || a[n] - a[n - 1] != 1)) { int newon = off[n] + on[0] - on[n] - 1; if (newon > ans) ans = newon; } printf("%d", ans); return 0; }
#include<stdio.h> #define ll long long ll a[100005]; ll b[100005]; ll c[100005]; ll d[100005]; int main() { ll i,n,m,s1=0,s2,max; scanf("%I64d%I64d",&n,&m); for(i=0;i<n;i++) scanf("%I64d",a+i); a[n]=m; b[0]=a[0]; for(i=1;i<=n;i++) b[i]=a[i]-a[i-1]; for(i=0;i<=n;i+=2) s1+=b[i]; max=s1; c[0]=b[0]; for(i=2;i<=n;i+=2) c[i]=c[i-2]+b[i]; if(n%2) { d[n]=b[n]; for(i=n-2;i>=0;i-=2) d[i]=d[i+2]+b[i]; } else { d[n-1]=b[n-1]; for(i=n-3;i>=0;i-=2) d[i]=d[i+2]+b[i]; } for(i=0;i<=n;i++) { s2=0; if(i%2&&b[i]>1) s2=c[i-1]+d[i]-1; if(i%2==0&&b[i]>1) s2=c[i]+d[i+1]-1; if(max<s2) max=s2; } /* for(i=0;i<=n;i++) printf("%d ",b[i]); printf("\n"); for(i=0;i<=n;i++) printf("%d ",c[i]); printf("\n"); for(i=0;i<=n;i++) printf("%d ",d[i]); printf("\n"); */ printf("%I64d",max); return 0; }
#include <stdio.h> #define max(a, b) ((a) > (b) ? (a) : (b)) __int64 array[100005] = {0}, left[100005] = {0}, right[100005] = {0}; int main() { int n, m; scanf("%d %d", &n, &m); int pre = 0, now, tag = n % 2; __int64 ans, temp; for (int i = 0; i < n; i++) { scanf("%d", &now); array[i] = now - pre; pre = now; } array[n] = m - pre; left[0] = array[0]; right[0] = 0; for (int i = 1; i <= n; i++) { if (i % 2) { left[i] = left[i - 1]; right[i] = right[i - 1] + array[i]; } else { left[i] = left[i - 1] + array[i]; right[i] = right[i - 1]; } } ans = left[n]; for (int i = 0; i <= n; i++) { if (array[i] == 1) continue; temp = left[i - 1] + right[n] - right[i - 1] - 1; ans = max(temp, ans); } printf("%lld\n", ans); return 0; }
#include <stdio.h> long long int max(long long int a, long long int b){ if(a>b) return a; return b; } int main(){ int n,m; scanf("%d %d",&n,&m); int s[n+2]; s[0] = 0; int i; for(i=1;i<=n;i++) scanf("%d",&s[i]); s[i] = m; int b[n+1]; for(i=1;i<n+2;i++){ b[i-1] = s[i] - s[i-1]; } long long int cum[n+2]; for (i = 0; i < n+2; ++i) { cum[i] = 0; } cum[0] = 0; cum[1] = b[0]; cum[2] = b[1]; i =3; while (i<n+2){ cum[i] = cum[i]+b[i-1]+cum[i-2]; i+=1; } long long int revcum[n+2],num; for (i = 0; i < n+2; ++i) { revcum[i] = 0; } revcum[n+1] = 0; revcum[n] = b[n]; revcum[n-1] = b[n-1]; i = n-2; while (i>=0){ revcum[i] +=b[i]+revcum[i+2]; i-=1; } num = revcum[0]; long long int temp; for(i=0;i<n+1;i++){ if (b[i] != 1){ temp = 0; if (i%2 == 1){ temp = cum[i] + revcum[i] -1; } else{ temp = cum[i+1] + revcum[i+1] - 1; } num = max(num,temp); } } printf("%lld",num); }
#include <stdio.h> #define MAX_COUNT 100005 int ends[MAX_COUNT]; int light[MAX_COUNT]; int max(int a, int b) { return a > b ? a : b; } int GetLight(int pos_left, int pos_right) { int res = light[pos_right] - light[pos_left]; if (pos_left % 2 == 1) { res += 1; } return res; } int GetDark(int pos_left, int pos_right) { return ends[pos_right] - ends[pos_left] - GetLight(pos_left, pos_right); } int main() { int count, right_limit; scanf("%d%d", &count, &right_limit); ends[0] = 0; ends[count + 1] = right_limit; light[0] = 0; int i; for (i = 1; i <= count; ++i) { scanf("%d", &ends[i]); light[i] = light[i - 1]; if (i % 2 == 1) { light[i] += ends[i] - ends[i - 1]; } } light[count + 1] = light[count]; if (count % 2 == 0) { light[count + 1] += ends[count + 1] - ends[count]; } int best = light[count + 1]; for (i = 0; i <= count; ++i) { if (ends[i] + 1 >= ends[i + 1]) { continue; } if (i % 2 == 0) { int new_light = GetLight(0, i) + 1; new_light += GetDark(i + 1, count + 1); best = max(best, new_light); new_light = GetLight(0, i + 1) - 1; new_light += GetDark(i + 1, count + 1); best = max(best, new_light); } else { int new_light = GetLight(0, i) + (ends[i + 1] - ends[i] - 1); new_light += GetDark(i + 1, count + 1); best = max(best, new_light); new_light = GetLight(0, i) + 1; new_light += GetDark(i + 1, count + 1); best = max(best, new_light); } } printf("%d\n", best); return 0; }
#include <stdio.h> #define MAX 100000 long a[MAX]; long d[MAX]; int main() { long N, M; scanf("%ld %ld", &N, &M); long i; for (i = 0; i < N; i++) { scanf("%ld", &a[i]); } long delta; delta = 0; for (i = 0; i <= N; i++) { if (i == 0) { d[i] = a[i]; } else if (i == N) { d[i] = M - a[N - 1]; } else { d[i] = a[i] - a[i - 1]; } } long key = 0; long ikey = 0; long result = 0; if (N % 2 == 1) { i = N; while (i > 0) { delta = delta - d[i]; i--; if (delta < key && delta < 0) { key = delta; ikey = i; } delta = delta + d[i]; i--; } if (key >= 0) { result = (delta + M) / 2; } else { result = (delta - 2 * key + M) / 2 - 1; } } else { i = N; while (i > 1) { delta = delta + d[i]; i--; delta = delta - d[i]; i--; if (delta < key && delta < 0) { key = delta; ikey = i; } } delta = delta + d[0]; if (key >= 0) { result = (delta + M) / 2; } else { result = (delta - 2 * key + M) / 2 - 1; } } printf("%ld\n", result); }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <ctype.h> #include <math.h> #define MAXSIZE 100000 int size, lights[MAXSIZE + 10], timeOff, diff[MAXSIZE + 10], forw[2][MAXSIZE + 10], backw[2][MAXSIZE + 10]; void findForw() { for(int i = size, j = 1; i >= 0; i--, j++) { if(j % 2 == 1) { forw[0][i] = lights[i + 1] - lights[i] + forw[0][i + 1]; forw[1][i] = forw[1][i + 1]; } else { forw[0][i] = forw[0][i + 1]; forw[1][i] = lights[i + 1] - lights[i] + forw[1][i + 1]; } } } void findBackw() { for(int i = 1, j = 1; i < size + 2; i++, j++) { if(j % 2 == 1) { backw[0][i] = lights[i] - lights[i - 1] + backw[0][i - 1]; backw[1][i] = backw[1][i - 1]; } else { backw[0][i] = backw[0][i - 1]; backw[1][i] = lights[i] - lights[i - 1] + backw[1][i - 1]; } } } int main() { scanf("%i %i", &size, &timeOff); lights[0] = 0; for(int i = 1; i < size + 1; i++) { scanf("%i", &lights[i]); } lights[size + 1] = timeOff; findForw(); findBackw(); int max = forw[0][0]; for(int i = 1; i < size + 2; i++) { int total1, total2; if(i % 2 == 1) { total1 = lights[i] - 1 != lights[i - 1] ? lights[i] - 1 - lights[i - 1] + backw[0][i - 1] + forw[0][i] : 0; if((size + 2 - i) % 2 == 0) { total2 = lights[i + 1] != lights[i] + 1 ? backw[0][i] + lights[i + 1] - (lights[i] + 1) + forw[0][i + 2] : 0; } else { total2 = lights[i + 1] != lights[i] + 1 ? backw[0][i] + lights[i + 1] - (lights[i] + 1) + forw[1][i + 2] : 0; } if(i == size + 1) { total2 = 0; } total1 = total1 > total2 ? total1 : total2; } else { total1 = lights[i] - 1 != lights[i - 1] ? backw[0][i - 1] + 1 + forw[0][i + 1] : 0; total2 = lights[i] + 1 != lights[i + 1] ? backw[0][i - 1] + 1 + forw[0][i + 1] : 0; if(i == size + 1) { total2 = 0; } total1 = total1 > total2 ? total1 : total2; } max = total1 > max ? total1 : max; } printf("%i", max); exit(0); }
#include <stdio.h> #include <stdlib.h> #define MAXM 400002 #define MAXN 200001 #define POINT_TYPE_START 0 #define POINT_TYPE_END 1 typedef struct { long long pos; int type; } point; int n; point A[MAXM]; long long marked[MAXN]; int cmp(void *_p1, void *_p2) { point p1 = *((point *) _p1); point p2 = *((point *) _p2); if (p1.pos < p2.pos) { return -1; } if (p2.pos < p1.pos) { return 1; } if (p1.type < p2.type) { return -1; } if (p2.type < p1.type) { return 1; } return 0; } int main() { int i; long long start_point, end_point; int m, current, closed, opened; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%I64d %I64d", &start_point, &end_point); A[i * 2].pos = start_point; A[i * 2].type = POINT_TYPE_START; A[i * 2 + 1].pos = end_point; A[i * 2 + 1].type = POINT_TYPE_END; } qsort(A, 2 * n, sizeof(A[0]), cmp); opened = 0; i = 0; m = 2 * n - 1; while (i < m) { current = i; closed = 0; while (current < m && A[current].pos == A[i].pos) { if (A[current].type == POINT_TYPE_START) { opened++; } else { closed++; } current++; } marked[opened]++; opened -= closed; marked[opened] += A[current].pos - A[i].pos - 1; i = current; } marked[opened]++; for (i = 1; i <= n; ++i) { printf("%I64d ", marked[i]); } printf("\n"); return 0; }
#define _USE_MATH_DEFINES #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdbool.h> #include <float.h> #include <limits.h> #include <malloc.h> #include <memory.h> #include <complex.h> #include <errno.h> #include <time.h> #define N 200005 long long ans[N*5],g[N*5],tt,suml,sumr; int i,n,c[N*5],d[N*5],t,j,max,ft[N*5],fi[N*5],ftt[N*5],fii[N*5],l,h[N*5]; struct u { long long a; int b; }a[N<<2]; int cmp(const void *x,const void *y) { long long a,b; a=((struct u *)x)->a; b=((struct u *)y)->a; if (a>b) return 1; else if (a<b) return -1; else return 0; } void add(int *a,int x,int y) { if (x==0) return; while (x<=max) { a[x]+=y; x+=x&(-x); } } long long all(int *a,int x) { long long res=0; while (x>0) { res+=a[x]; x-=x&(-x); } return res; } int main() { scanf("%d",&n); t=n<<1; for (i=1;i<=t;i+=2) { scanf("%lld %lld",&a[i].a,&a[i+1].a); a[i].b=i; a[i+1].b=i+1; } qsort(&a[1],t,sizeof(struct u),cmp); for (i=2,c[1]=1;i<=t;i++) if (a[i].a>a[i-1].a) c[i]=c[i-1]+1; else c[i]=c[i-1]; for (i=1,max=INT_MIN;i<=t;i++) { d[a[i].b]=c[i]; g[c[i]]=a[i].a; max=c[i]>max ? c[i] : max; } memset(h,0,sizeof(h)); memset(ans,0,sizeof(ans)); for (i=1;i<=t;i+=2) { add(ft,d[i],1); add(ft,d[i+1]+1,-1); add(fi,d[i],1*d[i]); add(fi,d[i+1]+1,-1*(d[i+1]+1)); add(ftt,d[i],1); add(ftt,d[i+1],-1); add(fii,d[i],1*d[i]); add(fii,d[i+1],-1*(d[i+1])); } for (i=1;i<max;i++) { suml=i*all(ft,i-1)-all(fi,i-1); sumr=(i+1)*all(ft,i)-all(fi,i); tt=sumr-suml; ans[tt]++; suml=i*all(ftt,i-1)-all(fii,i-1); sumr=(i+1)*all(ftt,i)-all(fii,i); tt=sumr-suml; ans[tt]+=g[i+1]-g[i]-1; } suml=max*all(ft,max-1)-all(fi,max-1); sumr=(max+1)*all(ft,max)-all(fi,max); tt=sumr-suml; ans[tt]++; for (l=1;l<=n;l++) printf("%lld ",ans[l]); puts(""); return 0; }
#include <stdio.h> #define M 998244353 #define MAX_N 1005 #define ll long long int n,arr[MAX_N],dp[MAX_N],C[MAX_N][MAX_N],i,j; void init_nCr(){ for(int n=0;n<=1001;n++) C[n][0]=C[n][n]=1; for(int n=2;n<=1001;n++) for(int r=1;r<n;r++) C[n][r]=(C[n-1][r-1]+C[n-1][r])%M; } int main(){ init_nCr(); for(scanf("%i",&n),i=n;i>0;i--) scanf("%i",&arr[i]); ll res,tmp; for(i=1;i<=n;i++,res=0){ if(arr[i]>0) for(j=i-arr[i]; j>0 ; j--) res=(res+((ll)C[i-j-1][arr[i]-1]*(1+dp[j-1]))%M)%M; dp[i]=(dp[i-1]+res)%M; } printf("%i\n", dp[n]); }
#include <stdlib.h> #include <stdio.h> int main(void) { long long int m = 998244353, a[1005], c[1005][1005] = {0}, n; scanf("%lld", &n); int i, j; for (i = 0; i <1005; i++) { c[i][0] = c[i][i] = 1; for (j = 1; j < i; j++) { c[i][j] = (c[i-1][j] + c[i-1][j-1]) % m; } } for (i = 0; i < n; i++) scanf("%lld", &a[i]); long long int dp[1005] = {0}; dp[n] = 1; for (i = n-1; i >= 0; i--) { if (a[i] <= 0) continue; for (j = i + a[i] + 1; j <= n; j++) { dp[i] += (c[j - i - 1][a[i]]*dp[j]) % m; dp[i] %= m; } } long long int ans = 0; for (i = 0; i < n; i++){ ans += dp[i]; ans %= m; } printf("%lld\n", ans); return 0; }
#include<stdio.h> #define M 998244353 int a[1007],n; int dp[1007]; int x[1007]; int c[1007][1007]; void init(){ int i,j; for(i=0;i<=1000;i++){ c[i][0]=1; c[i][i]=1; } for(i=2;i<=1000;i++){ for(j=1;j<i;j++){ c[i][j]=(c[i-1][j-1]+c[i-1][j])%M; } } } void run(){ int i,j; init(); while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++){ scanf("%d",&a[i]); } dp[n]=0; x[n]=0; for(i=n-1;i>=0;i--){ dp[i]=0; if(a[i]>0){ for(j=0;a[i]+i+j<n;j++){ dp[i]=(dp[i]+((long long)x[a[i]+i+j+1]+1)*c[a[i]-1+j][a[i]-1])%M; } } x[i]=(x[i+1]+dp[i])%M; } printf("%d\n",x[0]); } } main(){ #ifndef ONLINE_JUDGE freopen("e45d_min.in","rb",stdin); //freopen("e45d.in","rb",stdin); freopen("e45d_.out","wb",stdout); #endif run(); return 0; }
/* upsolve with Dukkha */ #include <stdio.h> #include <string.h> #define N 300000 #define M 300000 struct E { int i, j; char cut; } ee[M], ff[N]; struct L { struct L *next; struct E *e; }; struct V { struct L adj, adj_; int a, b; } vv[N]; void link(int i, struct E *e) { static struct L ll_[M * 2], *l = ll_; l->e = e; l->next = vv[i].adj.next; vv[i].adj.next = l++; } void link_(int i, struct E *e) { static struct L ll_[N * 2], *l = ll_; l->e = e; l->next = vv[i].adj_.next; vv[i].adj_.next = l++; } void dfs(int p, int i) { struct V *u = &vv[i]; static int t = 0; struct L *l; u->a = u->b = ++t; for (l = u->adj.next; l; l = l->next) { struct E *e = l->e; int j = i ^ e->i ^ e->j; struct V *v = &vv[j]; if (!v->a) { dfs(i, j); if (u->b > v->b) u->b = v->b; if (v->b > u->a) e->cut = 1; } else if (j != p) if (u->b > v->a) u->b = v->a; } } int dsu[N]; int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); } void join(int i, int j) { i = find(i); j = find(j); if (i == j) return; if (dsu[i] > dsu[j]) dsu[i] = j; else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; } } int d_, i_; void dfs_(int p, int i, int d) { struct L *l; if (d_ < d) { d_ = d; i_ = i; } d++; for (l = vv[i].adj_.next; l; l = l->next) { struct E *e = l->e; int j = i ^ e->i ^ e->j; if (j != p) dfs_(i, j, d); } } int main() { int n, m, h, i, j, cnt; scanf("%d%d", &n, &m); for (h = 0; h < m; h++) { struct E *e = &ee[h]; scanf("%d%d", &i, &j), i--, j--; e->i = i, e->j = j; link(i, e); link(j, e); } dfs(-1, 0); memset(dsu, -1, sizeof dsu); for (h = 0; h < m; h++) { struct E *e = &ee[h]; if (!e->cut) join(e->i, e->j); } cnt = 0; for (h = 0; h < m; h++) { struct E *e = &ee[h]; if (e->cut) { struct E *e_ = &ff[cnt++]; i = find(e->i), j = find(e->j); e_->i = i, e_->j = j; link_(i, e_); link_(j, e_); } } d_ = i_ = -1; dfs_(-1, find(0), 0); dfs_(-1, i_, 0); printf("%d\n", d_); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> //LCA //first/next抄来的,其实是把值相同的点连在一起 #define N 300007 #define TL (1<<19) #define L(x) ((x)<<1) #define R(x) (((x)<<1)+1) #define H(x,y) (((x)+(y))>>1) struct p{ long long i,j; char k; }tree[TL<<1]; struct q{ int l,r; }a[N<<1]; struct r{ int l,r,c,x,y,y_; }r__[N]; int p[N],n,m,l_,y_; long long r_; int first[N],next[N<<1]; void init(int h,int l,int r){ tree[h].i=0; tree[h].j=0; tree[h].k=0; if(r-l==1){ return; } init(L(h),l,H(l,r)); init(R(h),H(l,r),r); } void update(int h,int l,int r,int i,int j,int x){ tree[h].j+=(long long)(j-i)*x; if(r-l==j-i){ tree[h].i+=x; tree[h].k=1; return; } if(j<=H(l,r)){ update(L(h),l,H(l,r),i,j,x); return; } if(i>=H(l,r)){ update(R(h),H(l,r),r,i,j,x); return; } update(L(h),l,H(l,r),i,H(l,r),x); update(R(h),H(l,r),r,H(l,r),j,x); } void query(int h,int l,int r,int i,int j){ if(tree[h].k==1&&r-l>j-i) r_+=(long long)(j-i)*tree[h].i; if(r-l==j-i){ r_+=tree[h].j; return; } if(j<=H(l,r)){ query(L(h),l,H(l,r),i,j); return; } if(i>=H(l,r)){ query(R(h),H(l,r),r,i,j); return; } query(L(h),l,H(l,r),i,H(l,r)); query(R(h),H(l,r),r,H(l,r),j); } int find_(int i,int j,int c){ int k,x,x_,y_; x_=-1; y_=-1; x=1; for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==i){ if(x_<r__[a[k].r].r-r__[a[k].r].l){ x_=r__[a[k].r].r-r__[a[k].r].l; y_=a[k].r; } } } if(y_!=-1){ x+=find_(y_,j+x,c); } for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==i){ if(a[k].r!=y_){ x+=find_(a[k].r,j+x,a[k].r); } } } r__[i].l=j; r__[i].r=j+x; r__[i].x=c; return x; } int find(int i,int j,int c){ int k,x; x=1; for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==-1){ p[a[k].r]=i; x+=find(a[k].r,j+x,c+1); } } r__[i].l=j; r__[i].r=j+x; r__[i].c=c; return x; } void update_(int i,int j,int x){ while(1){ if(r__[i].x==r__[j].x){ if(r__[i].c<r__[j].c){ update(1,0,y_,r__[i].l+1,r__[j].l+1,x); }else if(r__[i].c>r__[j].c){ update(1,0,y_,r__[j].l+1,r__[i].l+1,x); } break; } if(r__[r__[i].x].c<r__[r__[j].x].c){ update(1,0,y_,r__[r__[j].x].l,r__[j].l+1,x); j=p[r__[j].x]; }else{ update(1,0,y_,r__[r__[i].x].l,r__[i].l+1,x); i=p[r__[i].x]; } } } void query_(int i){ r_=0; query(1,0,y_,r__[i].l,r__[i].l+1); } int find__(int i,int j){ int k,k_,x,y,y_,y__; x=1; k_=-1; y=0; y_=0; for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==i){ x+=find__(a[k].r,j+x); query_(a[k].r); y__=(r_==0?1:0)+r__[a[k].r].y; if(y<y__){ k_=k; y=y__; } continue; } if(p[i]==a[k].r){ continue; } update_(i,a[k].r,1); } for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==i&&k!=k_){ query_(a[k].r); y__=(r_==0?1:0)+r__[a[k].r].y; if(y_<y__){ y_=y__; } } } r__[i].y=y; r__[i].y_=y+y_; return x; } void cat(){ int i,r; for(i=0;i<N;i++){ first[i]=-1; } memset(next,0,sizeof(next)); for(i=l_-1;i>=0;i--){ next[i]=first[a[i].l]; first[a[i].l]=i; } for(i=0;i<n;i++){ p[i]=-1; } p[0]=0; find(0,0,0); find_(0,0,0); for(y_=1;y_<n;y_<<=1); init(1,0,y_); find__(0,0); r=0; for(i=0;i<n;i++){ if(r<r__[i].y_){ r=r__[i].y_; } } printf("%d\n",r); } void run(){ int i,l,r; while(scanf("%d%d",&n,&m)!=EOF){ l_=0; for(i=0;i<m;i++){ scanf("%d%d",&l,&r); a[l_].l=l-1; a[l_].r=r-1; a[l_+1].l=r-1; a[l_+1].r=l-1; l_+=2; } cat(); } } main(){ #ifndef ONLINE_JUDGE freopen("e45e_min.in","rb",stdin); freopen("e45e_.out","wb",stdout); #endif run(); return 0; }
#include <stdio.h> #include <stdlib.h> typedef struct IntListNode_m { int value; struct IntListNode_m *next; } IntListNode; typedef struct IntList_m { IntListNode *start; int size; } IntList; IntListNode* CreateIntListNode(int value) { IntListNode *new_node = (IntListNode*)malloc(sizeof(IntListNode)); new_node->value = value; new_node->next = NULL; return new_node; } void AddToIntList(IntList *list, int value) { IntListNode *new_node = CreateIntListNode(value); new_node->next = list->start; list->start = new_node; list->size += 1; } void FreeIntList(IntList *list) { while (list->start != NULL) { IntListNode *to_delete = list->start; list->start = to_delete->next; free(to_delete); } } typedef struct GraphNode_m { int time; int lowpoint; int component_id; IntList edges; } GraphNode; typedef GraphNode* Graph; void InitGraph(Graph graph, int nodes) { int i; for (i = 0; i < nodes; ++i) { graph[i].time = 0; graph[i].lowpoint = 0; graph[i].component_id = -1; graph[i].edges.start = NULL; graph[i].edges.size = 0; } } void FreeGraph(Graph graph, int nodes) { int i; for (i = 0; i < nodes; ++i) { FreeIntList(&graph[i].edges); } } void AddGraphEdge(Graph graph, int node1, int node2) { AddToIntList(&graph[node1].edges, node2); AddToIntList(&graph[node2].edges, node1); } typedef struct EdgeStackNode_m { int node1; int node2; struct EdgeStackNode_m *next; } EdgeStackNode; typedef EdgeStackNode* EdgeStack; EdgeStackNode* CreateEdgeStackNode(int node1, int node2) { EdgeStackNode *new_node = (EdgeStackNode*)malloc(sizeof(EdgeStackNode)); new_node->node1 = node1; new_node->node2 = node2; new_node->next = NULL; return new_node; } void PushOntoEdgeStack(EdgeStack *stack, int node1, int node2) { EdgeStackNode *new_node = CreateEdgeStackNode(node1, node2); new_node->next = *stack; *stack = new_node; } void PopFromEdgeStack(EdgeStack *stack) { if (*stack == NULL) { return; } EdgeStackNode *to_delete = *stack; *stack = to_delete->next; free(to_delete); } void EdgeStackTop(EdgeStack *stack, int *node1, int *node2) { if (stack != NULL) { *node1 = (*stack)->node1; *node2 = (*stack)->node2; } } int ExtractComponent(Graph graph, EdgeStack *stack, int end1, int end2) { static int assigned_comps = 0; int new_comp = assigned_comps; int node1, node2; EdgeStackTop(stack, &node1, &node2); if (node1 == end1 && node2 == end2) { PopFromEdgeStack(stack); return 0; } do { EdgeStackTop(stack, &node1, &node2); PopFromEdgeStack(stack); graph[node1].component_id = new_comp; graph[node2].component_id = new_comp; } while (node1 != end1 || node2 != end2); assigned_comps += 1; return 1; } int Tarjan(Graph graph, int node, int father, EdgeStack *stack) { static int time = 0; graph[node].time = graph[node].lowpoint = ++time; int comps = 0; IntListNode *it = graph[node].edges.start; while (it != NULL) { int other = it->value; it = it->next; if (other == father) { continue; } if (graph[other].time == 0) { PushOntoEdgeStack(stack, node, other); comps += Tarjan(graph, other, node, stack); if (graph[other].lowpoint >= graph[node].time) { comps += ExtractComponent(graph, stack, node, other); } if (graph[other].lowpoint < graph[node].lowpoint) { graph[node].lowpoint = graph[other].lowpoint; } } else if (graph[other].time < graph[node].lowpoint) { graph[node].lowpoint = graph[other].time; } } return comps; } int FindComponents(Graph graph, int nodes) { EdgeStack stack = NULL; int assigned_comps = Tarjan(graph, 0, -1, &stack); int i; for (i = 0; i < nodes; ++i) { if (graph[i].component_id == -1) { graph[i].component_id = assigned_comps; assigned_comps += 1; } } return assigned_comps; } int max(int a, int b) { return a > b ? a : b; } void UpdateTwoMax(int new_val, int *max1, int *max2) { if (new_val > *max1) { *max2 = *max1; *max1 = new_val; } else if (new_val > *max2) { *max2 = new_val; } } int FindLongestPath(Graph tree, int root, int *long_son) { tree[root].time = 1; int longest = 0; int longest_son1 = 0; int longest_son2 = 0; IntListNode *it = tree[root].edges.start; while (it != NULL) { int other = it->value; it = it->next; if (!tree[other].time) { int new_son; int new_length = FindLongestPath(tree, other, &new_son); longest = max(longest, new_length); UpdateTwoMax(new_son, &longest_son1, &longest_son2); } } *long_son = longest_son1 + 1; longest = max(longest, longest_son1 + longest_son2); return longest; } #define MAX_NODES 300000 GraphNode graph[MAX_NODES]; GraphNode tree[MAX_NODES]; int main() { int nodes, edges; scanf("%d%d", &nodes, &edges); InitGraph(graph, nodes); int i; for (i = 0; i < edges; ++i) { int node1, node2; scanf("%d%d", &node1, &node2); AddGraphEdge(graph, node1 - 1, node2 - 1); } int component_count = FindComponents(graph, nodes); InitGraph(tree, component_count); for (i = 0; i < nodes; ++i) { int i_comp = graph[i].component_id; IntListNode *it = graph[i].edges.start; while (it != NULL) { int other = it->value; int other_comp = graph[other].component_id; it = it->next; if (i < other && i_comp != other_comp) { AddGraphEdge(tree, i_comp, other_comp); } } } FreeGraph(graph, nodes); int result_aux; int result = FindLongestPath(tree, 0, &result_aux); printf("%d\n", result); FreeGraph(tree, component_count); return 0; }
/* practice with Dukkha */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 500000 #define N_ (1 << 19) /* N_ = pow2(ceil(log2(N))) */ #define M 500000 #define A 500000 int n; int ll[M], rr[M], hh[A + 1], xx[M]; int compare(const void *a, const void *b) { int i = *(int *) a; int j = *(int *) b; return rr[i] - rr[j]; } int pp[N + 1], tt[N_ * 2]; void pull(int k) { int t1 = tt[k * 2 + 1], t2 = tt[k * 2 + 2]; tt[k] = pp[t1] <= pp[t2] ? t1 : t2; } void build(int k, int l, int r) { int m; if (r - l == 1) { tt[k] = l; return; } m = (l + r) / 2; build(k * 2 + 1, l, m); build(k * 2 + 2, m, r); pull(k); } void update(int k, int l, int r, int i) { int m; if (r - l == 1) { pp[i] = i; return; } m = (l + r) / 2; if (i < m) update(k * 2 + 1, l, m, i); else update(k * 2 + 2, m, r, i); pull(k); } int query(int k, int l, int r, int ql, int qr) { int m, t1, t2; if (qr <= l || r <= ql) return n; if (ql <= l && r <= qr) return tt[k]; m = (l + r) / 2; t1 = query(k * 2 + 1, l, m, ql, qr); t2 = query(k * 2 + 2, m, r, ql, qr); return pp[t1] <= pp[t2] ? t1 : t2; } int main() { static int aa[N]; int m, h, h_, i, l, r, r_, a, p; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); scanf("%d", &m); for (h = 0; h < m; h++) { scanf("%d%d", &l, &r), l--; ll[h] = l, rr[h] = r; } memset(hh, -1, sizeof hh); for (i = 0; i < n; i++) { a = aa[i]; pp[i] = hh[a]; hh[a] = i; } pp[n] = n; for (h = 0; h < m; h++) hh[h] = h; qsort(hh, m, sizeof *hh, compare); build(0, 0, n); r_ = 0; for (h_ = 0; h_ < m; h_++) { h = hh[h_]; l = ll[h], r = rr[h]; while (r_ < r) { if ((p = pp[r_]) >= 0) update(0, 0, n, p); r_++; } i = query(0, 0, n, l, r); if (pp[i] < l) xx[h] = aa[i]; } for (h = 0; h < m; h++) printf("%d\n", xx[h]); return 0; }
#include<stdlib.h> #include<stdio.h> #include<string.h> #include<time.h> #define MAX_N 500000 #define PART 1000 typedef struct _Query { int l; int r; int a; } Query; Query queries[MAX_N]; int a[MAX_N + 1]; int indexes[MAX_N]; int cnt[MAX_N]; int summary[PART]; int Compare(const void *a, const void *b) { int i1 = *(int*)a; int i2 = *(int*)b; int c = queries[i1].l / PART - queries[i2].l / PART; return c ? c : (queries[i1].r - queries[i2].r); } inline void Add(int i) { cnt[i]++; switch (cnt[i]) { case 1: summary[i / PART]++; break; case 2: summary[i / PART]--; break; } } inline void Remove(int i) { cnt[i]--; switch (cnt[i]) { case 0: summary[i / PART]--; break; case 1: summary[i / PART]++; break; } } inline int Qry() { for (int i = 0; i < PART; i++) { if (summary[i] != 0) { for (int j = i * PART; ; j++) { if (cnt[j] != 1) { continue; } return j; } } } return 0; } void Solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", a + i); } int q; scanf("%d", &q); for (int i = 0; i < n; i++) { scanf("%d %d", &(queries[i].l), &(queries[i].r)); indexes[i] = i; } qsort(indexes, q, sizeof(int), Compare); int l = queries[indexes[0]].l; int r = queries[indexes[0]].l - 1; for (int i = 0; i < q; i++) { int left = queries[indexes[i]].l; int right = queries[indexes[i]].r; while (l > left) { Add(a[--l]); } while (r < right) { Add(a[++r]); } while (l < left) { Remove(a[l++]); } while (r > right) { Remove(a[r--]); } queries[indexes[i]].a = Qry(); } for (int i = 0; i < q; i++) { printf("%d ", queries[i].a); } } int main() { #ifndef ONLINE_JUDGE freopen("E:\\DATABASE\\TESTCASE\\CR46F.in", "r", stdin); freopen("E:\\DATABASE\\TESTCASE\\CR46F.out", "w", stdout); #endif Solve(); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_N 500500 #define Min_node(a,b) (a.l>b.l?b:a) #define INF 6e5 typedef struct {int l, v;} node; int n,q,i,j,arr[MAX_N],last[MAX_N],Q[MAX_N][2],S[MAX_N]; node seg[4*MAX_N]; int ReadInt(); void WriteInt(int n); inline int ReadInt(){ int i= 0; char c= 0; char flag= 1; while((c<'0'||c>'9')&& c!='-')c=getchar(); if(c=='-'){flag=0;c=getchar();} for(;c>='0'&&c<='9';c= getchar()) i=i*10+c-'0'; if(!flag)i=-i; return i; } inline void WriteInt(int n){ if ( n < 0 ){putchar( '-' ); WriteInt( -n ); return;} if ( n < 10 ) putchar( n + '0' ); else {WriteInt( n / 10 );putchar( n % 10 + '0' );} } int cmp(const void *a, const void *b) {return Q[*(int *)a][1] - Q[*(int *)b][1];} node build(int p, int L, int R){ if(L==R) return seg[p]=(node){INF,arr[L]}; node a = build(p<<1, L, (L+R)/2); node b = build((p<<1)+1, (L+R)/2+1, R); return seg[p]=Min_node(a,b); } node UPD(int p, int L, int R, int idx, int l){ if(idx<L || idx>R) return seg[p]; if(idx==L && idx==R) return seg[p]=(node){l, seg[p].v}; node a = UPD((p<<1), L, (L+R)/2, idx, l); node b = UPD((p<<1)+1, (L+R)/2+1, R, idx, l); return seg[p]=Min_node(a,b); } node RMQ(int p, int L, int R, int i, int j){ if(i>R || j<L) return (node){INF, 0}; if(L>=i && R<=j) return seg[p]; node a = RMQ( p<<1, L, (L+R)/2, i, j); node b = RMQ((p<<1)+1,(L+R)/2+1, R, i, j); return Min_node(a,b); } int main(){ for(n=ReadInt(),i=1;i<=n;i++) arr[i]=ReadInt(); for(q=ReadInt(),i=0;i<q;i++) Q[i][0]=ReadInt(), Q[i][1]=ReadInt(), S[i]=i; qsort(S, q, sizeof(int), cmp); build(1, 1, n); for(i=1;i<=n;i++){ UPD(1, 1, n, i, last[arr[i]]); if(last[arr[i]]) UPD(1, 1, n, last[arr[i]], INF); last[arr[i]]=i; while(Q[S[j]][1]==i){ if(j==q) {i=INF;break;} node ans = RMQ(1, 1, n, Q[S[j]][0], i); if(ans.l<Q[S[j]][0]) Q[S[j]][0]=ans.v; else Q[S[j]][0]=0; j++; } } for(i=0;i<q;i++) printf("%i\n",Q[i][0]); }
#include <stdio.h> #define N 300000 long long max(long long a, long long b) { return a > b ? a : b; } int oo[1 + (N - 1) * 2], oj[1 + (N - 1) * 2], ow[1 + (N - 1) * 2]; int link(int o, int j, int w) { static int _ = 1; oo[_] = o, oj[_] = j, ow[_] = w; return _++; } int ae[N], aa[N], dd[N], pp[N], qq[N], sz[N]; long long vv[N], dp[N], dq[N], dr[N], ds[N]; void dfs(int p, int v, int i, int d) { int o, s; long long x; dd[i] = d + 1, pp[i] = p; vv[i] = v; s = 1; x = aa[i]; for (o = ae[i]; o; o = oo[o]) { int j = oj[o], w = ow[o]; if (j != p) { dfs(i, w, j, d + 1); s += sz[j]; x += dq[j]; } } sz[i] = s; dp[i] = x; dq[i] = p == -1 ? 0 : max(dp[i] - v * 2, 0); } void dfs_(int p, int i, int q, long long x, long long y) { int o, j_; qq[i] = q; dr[i] = x; ds[i] = y += dp[i] - dq[i] - vv[i]; j_ = -1; for (o = ae[i]; o; o = oo[o]) { int j = oj[o]; if (j != p) if (j_ == -1 || sz[j_] < sz[j]) j_ = j; } for (o = ae[i]; o; o = oo[o]) { int j = oj[o], w = ow[o]; if (j != p) dfs_(i, j, j == j_ ? q : j, max(x + dp[i] - dq[j] - w * 2, 0), y); } } int lca(int i, int j) { while (qq[i] != qq[j]) if (dd[qq[i]] > dd[qq[j]]) i = pp[qq[i]]; else j = pp[qq[j]]; return dd[i] < dd[j] ? i : j; } int main() { int n, q, h, i, j; scanf("%d%d", &n, &q); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (h = 0; h < n - 1; h++) { int w; scanf("%d%d%d", &i, &j, &w), i--, j--; ae[i] = link(ae[i], j, w); ae[j] = link(ae[j], i, w); } dfs(-1, 0, 0, 0); dfs_(-1, 0, 0, 0, 0); while (q--) { int a; scanf("%d%d", &i, &j), i--, j--; a = lca(i, j); printf("%lld\n", (ds[i] + ds[j] - ds[a] * 2) + dp[a] + dr[a]); } return 0; }
coins[102],n,max,c; main() { scanf("%d", &n); while(n--) { scanf("%d", &c); coins[c]++; if(max < coins[c]) max = coins[c]; } printf("%d\n", max); }
#include <stdio.h> int freq[101], n, x, mxfq = 1; main() { scanf("%d", &n); while (n--) { scanf("%d", &x); if (++freq[x] > mxfq) mxfq = freq[x]; } printf("%d", mxfq); }
#include<stdio.h> main(){ int n,i,a[100],b[101]={0}; scanf("%d",&n); while(n--){ scanf("%d",&a[n]); b[a[n]]++; } for(i=100;i>0;i--){ if(b[i]>b[i-1]) b[i-1]=b[i]; } printf("%d\n",b[0]); return 0; }
#include<stdio.h> int main () { int n; scanf("%d",&n); int a,c[101]={0},k=0; while(n--) { scanf("%d",&a); c[a]++; if(c[a]>k) k=c[a]; } printf("%d\n",k); }
#include <stdio.h> int n, ans=0, arr[100], a; int main(){ fscanf(stdin,"%d",&n); for(int i=0;i<n;i++){ fscanf(stdin,"%d",&a); arr[a-1]++; if(arr[a-1]>ans){ ans=arr[a-1]; } } fprintf(stdout,"%d",ans); return 0; }
#include<stdio.h> int A[105]; int main(){ int N; scanf("%d",&N); int num; while(N--){ scanf("%d",&num); A[num]+=1; } int max=-1; for(int i=0; i<101; i++){ if(A[i]>max){ max=A[i]; } } printf("%d\n",max); }
#include<stdio.h> int main() { int a[101]={0},n,i,pocket=0,value; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&value); a[value]++; if(a[value]>pocket) pocket=a[value]; } printf("%d",pocket); return 0; }
#include<stdio.h> int main() {int n,c,i,j,k,m,l,a[101]={0},b[101]={0}; scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d",&a[i]); c=0;m=0; for (i=1;i<=n;i++) {c=0; for (j=1;j<=n;j++) if (a[i]==a[j]) c++; if (c>m) m=c; } printf("%d",m); return (0); }
#include<stdio.h> main() { int k,n,j,i,c; scanf("%d",&n); int a[100]; for(i=0;i<n;i++) scanf("%d",&a[i]); int m=1; for(k=0;k<n;k++) { for(i=0;i<n;i++) { c=0; for(j=0;j<n;j++) { if(a[j]==a[i]) c++; } if(m<c) m=c; } } printf("%d",m); }
#include<stdio.h> #include<stdlib.h> int main() { long long int i,max=0,r,a[100000],freq[100000]={0}; scanf("%lld",&r); for(i=0;i<r;i++) { scanf("%lld",&a[i]); freq[a[i]]+=1; if(freq[a[i]]>max) max=freq[a[i]]; } printf("%lld",max); }
#include <stdio.h> #include <string.h> int Last[110]; int N,As[110]; int main() { scanf("%d",&N); int wi; for(wi=1;wi<=N;++wi)scanf("%d",As+wi); int Ans=1; for(wi=1;wi<=N;++wi) { ++Last[As[wi]]; if(Last[As[wi]]>Ans) Ans=Last[As[wi]]; } printf("%d\n",Ans); return 0; }
#include <stdio.h> int main(void) { // your code goes here int n,i,a[100],c=0,j,cmax=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",a+i); for(i=0;i<n;i++) { c=1; for(j=(i+1);j<n;j++) { if(a[i]==a[j]) c++; } if(c>cmax) cmax=c; } printf("%d\n",cmax); return 0; }
#include<stdio.h> int main(void) { int num[101] = { 0 }; int number[101], m, n, t; scanf("%d", &m); for (t = 1; t <=m; t++) { scanf("%d", &number[t]); } for (t = 1; t <=m; t++) { num[number[t]]++; } n = 0; for (t = 1; t <=100; t++) { if (num[t] > n) { n = num[t]; } } printf("%d\n", n); }
#include<stdio.h> #define PROB "a" int dau[105]={0}; int maxx=0; int n; void Nhap() { int tmp; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&tmp); dau[tmp]++; if(dau[tmp]>maxx) maxx=dau[tmp]; } printf("%d",maxx); } int main() { //init(); Nhap(); }
#include<stdlib.h> #include<stdio.h> int main(){ int *Freq,*arr; Freq=calloc(101,sizeof(int)); int n,max=0; arr=malloc(n*sizeof(int)); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",arr+i); Freq[arr[i]]++; } for(int i=0;i<101;i++){if(Freq[i]>max){max=Freq[i];}} printf("%d\n",max); }
#include<stdio.h> int main() { int n; int num[100], count[101]={0,}; scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d", &num[i]); for(int i=1; i<=100; i++){ for(int j=0; j<n; j++){ if(i==num[j]) count[i]++; } } int max=0; for(int i=1; i<=100; i++){ if(max<count[i]) max=count[i]; } printf("%d", max); }
#include<stdio.h> int main() { int a[100],i,j,n,st,put; while(~scanf("%d",&n)) { for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(put=0,i=0;i<n;i++) { for(j=0,st=0;j<n;j++) { if(a[i]==a[j]) { st++; } } if(put<st) { put=st; } } printf("%d\n",put); } }
#include<stdio.h> int main() { int n; scanf("%d",&n); int array [101]={0}; int temp,max_frequency=0; for(int i=0;i<n;i++) { scanf("%d",&temp); array [temp]++; if(array[temp]>max_frequency){ max_frequency=array[temp]; } } printf("%d",max_frequency); return 0; }
#include<stdio.h> int main() { int n,arr[100],cnt_array[101]={0},max; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&arr[i]); for(int i=0;i<n;i++) cnt_array[arr[i]]++; max=cnt_array[0]; for(int i=0;i<101;i++) if(cnt_array[i]>max) max=cnt_array[i]; printf("%d",max); }
#include <stdio.h> int main() { int nCoins, aCoin, mxo = 0; int oCoinValues[101] = {}; scanf("%d", &nCoins); for (int i = 0; i < nCoins; ++i) { scanf("%d", &aCoin); ++oCoinValues[aCoin]; if (oCoinValues[aCoin] > mxo) { ++mxo; } } printf("%d", mxo); return 0; }
#include<stdio.h> int main() { int N; scanf("%d", &N); int freq[100]={0}; for(int t=0; t<N; ++t) { int temp; scanf("%d", &temp); ++freq[temp-1]; } int maxFreq=0; for(int y=0; y<100; ++y) if(freq[y]>maxFreq) maxFreq = freq[y]; printf("%d\n", maxFreq); return 0; }
#include<stdio.h> int main() { int n,a,b,temp,max; scanf("%d",&n); int s[n]; temp=1; max=1; for(a=0;a<n;a++) { scanf("%d",&s[a]); } for(a=0;a<n;a++) { temp=1; for(b=a+1;b<n;b++) { if(s[a]==s[b]) { temp++; } } if(temp>=max) { max=temp; } } printf("%d",max); return 0; }
#include<stdio.h> int main() { int n, i; scanf("%d", &n); int a[101], freq[101]; for(i = 0; i < 101; ++i){ freq[i] = 0; } int mx = -1; for(i = 0; i < n; ++i){ scanf("%d", &a[i]); freq[a[i]]++; if(freq[a[i]] > mx){ mx = freq[a[i]]; } } printf("%d\n", mx); }
#include <stdio.h> #include <stdlib.h> int main() { int array[101], max; int num, nums; max = 0; memset(array, 0, sizeof(array)); scanf("%d",&num); for(int i=0; i<num; i++){ scanf("%d", &nums); array[nums]++; max = array[nums] > max ? array[nums]: max; } printf("%d\n",max); return 0; }
#include <stdio.h> int main(){ int n,number[100],i,j,k,sum=0,max=0; scanf("%d",&n); for(k=0;k<n;++k){ scanf("%d",&number[k]); } for(i=0;i<n;++i){ for(j=0;j<n;++j){ if(i!=j){ if(number[i]==number[j]) sum=sum+1; } } if(max<sum) max=sum; sum=0; } printf("%d",max+1); }
#include <stdio.h> #include<stdlib.h> int main() { int n; scanf("%i",&n); int *ar=(int*)calloc(sizeof(int),n); int *hash=(int*)calloc(sizeof(int),101); int i=0,max=0; for(;i<n;i++) { scanf("%i",&ar[i]); hash[ar[i]]++; if(hash[ar[i]]>max) max=hash[ar[i]]; } printf("%i",max); return 0; }
#include <stdio.h> #include <stdlib.h> int main() { int i=0, nb_coins=0, coin_value=0, coin[100]={0}, nb_pockets=0; scanf("%d",&nb_coins); for(i=0;i<nb_coins;i++) { scanf("%d",&coin_value); coin[coin_value-1]++; if(coin[coin_value-1]>nb_pockets) nb_pockets++; } printf("%d",nb_pockets); return 0; }
#include<stdio.h> #include<conio.h> main() { int n,temp,ans; int i,j; int max[100]; int a[100]; scanf("%d",&n); printf("\n"); for(i=0;i<n;i++) scanf("%d ",&a[i]); for(i=0;i<n;i++) max[i]=0; for(i=0;i<n;i++) {ans=a[i] ; for(j=0;j<n;j++) {if(ans==a[j]) max[i]=max[i]+1;} } temp=max[0]; for(i=1;i<n;i++) { if(max[i]>temp) temp=max[i]; } printf("%d",temp); }
#include<stdio.h> int str[101]; int main() { int n; scanf("%d",&n); int ara[n],i,p,max; for(i=0;i<n;i++) { scanf("%d",&ara[i]); str[ara[i]]++; } for(p=0;p<101;p++) { if(p==0) max=str[p]; else { if(str[p]>max) max=str[p]; } } printf("%d\n",max); return 0; }
#include<stdio.h> #include<string.h> int main() { int t,i,sum=0; int nums[120]; int temp[120]; scanf("%d",&t); memset(temp,0,sizeof(temp)); for(i=0;i<t;i++) { scanf("%d",&nums[i]); temp[nums[i]]++; } for(i=0;i<120;i++) { if(temp[i]>sum) sum=temp[i]; } printf("%d",sum); return 0; }
#include <stdio.h> int main() { int n,i,g,s=0,k,max=0,flag=1; scanf("%d",&n);int a[n]; if (n==1) flag=0; if(flag==0){ printf("1");} else{ for (i=0;i<n;i++){ scanf("%d",&a[i]);} for(i=0;i<n;i++){ k=a[i];if (max<s)max=s;s=0; for (g=0;g<n;g++){ if (a[g]==k)s++;}} printf("%d",max);} return 0; }
#include<stdio.h> int main() { int a,b,c,i,j,k,t,e[103],g[105]; scanf("%d",&a); for(i=0;i<a;i++) scanf("%d",&e[i]); for(j=0;j<a;j++) { b=1; for(k=j+1;k<a;k++) { if(e[j]==e[k]) { b++; } } g[j]=b; } for(i=0;i<a-1;i++) for(c=0;c<a-i-1;c++) if(g[c]>g[c+1]) { t=g[c]; g[c]=g[c+1]; g[c+1]=t; } printf("%d",g[a-1]); }
#include <stdio.h> #define MAX 1000 int main() { int len, coins[MAX] = {0}, pocket=1, index, bigger=0, value; scanf("%d", &len); for(len=len-1;len>=0;len--) { scanf("%d", &value); coins[value]++; } for(index=1;index<=100;index++) { if(bigger<coins[index]) { bigger = coins[index]; } } if(bigger<coins[index]) bigger = coins[index]; printf("%d\n", bigger); return 0; }
#include <stdio.h> short C[101]; int main() { short i; for(i = 1; i <= 100; ++i) { C[i] = 0; } short n, current; scanf("%hd", &n); for(i = 0; i < n; ++i) { scanf("%hd", &current); ++C[current]; } short max = 0; for(i = 1; i <= 100; ++i) { if(C[i] > max) max = C[i]; } printf("%hd", max); return 0; }
#if 01 #include<stdio.h> #define MAX (101) int n; int num[MAX]; int main(void){ int x; int pocket = 0; scanf("%d", &n); for (int i = 0; i < n; i++){ scanf("%d", &x); num[x]++; } int change = 1; while (change){ change = 0; pocket++; for (int i = 1; i < MAX; i++){ if (num[i]){ num[i]--; change = 1; } } } printf("%d", pocket - 1); return 0; } #endif
#include<stdio.h> int main() { int ara[102],count[102],max; int i,j,n; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&ara[i]); } for(i=1;i<=100;i++){ count[i]=0; } for(i=0;i<n;i++){ count[ara[i]]++; } max=count[1]; for(i=2;i<=100;i++){ if(count[i]>max) max=count[i]; } printf("%d\n",max); }
#include<stdio.h> main() { int n; scanf("%d",&n); int j,i,s[n]; for(i=0;i<n;i++) scanf("%d",&s[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(s[i]>s[j]) { int t=s[i]; s[i]=s[j]; s[j]=t; } } } int count=1,l=1; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(s[i]==s[j]) count++; else break; } if(count>l) l=count; count=1; } printf("%d",l); }
#include<stdio.h> #include<stdlib.h> int main(void){ int a; scanf("%d",&a); int array[100]; for(int i=0;i<a;i++){ scanf("%d",&array[i]); } int lolCount = 0, j, k; for (j = 0; j < a; ++j) { int count = 0; for (k = 0; k < a; ++k) { if (array[k] == array[j]) ++count; } if (count > lolCount) { lolCount = count; } } printf("%d",lolCount); return 0; }
#include<stdio.h> int main(){ int n,pockets=0,count,same; int arr[100]; scanf("%d",&n); count=0; while(count<n)scanf("%d",&arr[count++]); count=0; while(count<n){ int c=0; same=0; while(c<n){ if(arr[count]==arr[c])same++; c++; } pockets=same>pockets?same:pockets; count++; } printf("%d",pockets); return 0; }
#include <stdio.h> int main() { int i,j,k,temp,a=1,cnt,b=0; int h[100]; scanf ("%d",&j); for (i=0;i<j;i++) { scanf ("%d",&h[i]); } for (i=0;i<j;i++) { temp=h[i]; h[i]=0; for (k=0;k<j;k++) { if (temp==h[k]) a++; } h[i]=temp; if (a>b) b=a; a=1; } printf("%d",b); }
#include "stdio.h" #define MAX_NUMBER 101 #define BASE "%d" typedef int Base; int main() { Base NumberCount[MAX_NUMBER] = { 0 }; Base Coins = 0; Base Value = 0; Base Pockets = 0; scanf(BASE, &Coins); while (Coins--) { scanf(BASE, &Value); if (++NumberCount[Value] > Pockets) { Pockets = NumberCount[Value]; } } printf(BASE"\n", Pockets); return 0; }
#include<stdio.h> #include<string.h> #define sc(x) {register char c7=getchar(),v7=1;for(x=0;c7<48||c7>57;c7=getchar())if(c7==45)v7=-1;for(;c7>=48&&c7<=57;x=(x<<1)+(x<<3)+c7-48,c7=getchar());x*=v7;} int hash[123]; int main(){ int n; int i,tp; scanf("%d",&n); for(i=0; i<n; i++) { sc(tp) hash[tp]++; } int max = 0; for(i=1; i<=100; i++) { if(hash[i]>max) max = hash[i]; } printf("%d\n",max); }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <stdbool.h> int N, coins[1000], visited[100000]; int main() { scanf("%i", &N); for(int i = 0; i < N; i++) { scanf("%i", &coins[i]); visited[coins[i]]++; } int max = 0; for(int i = 0; i < 100000; i++) { if(visited[i] > max) { max = visited[i]; } } printf("%i", max); exit(0); }
#include <stdio.h> #include <stdlib.h> int main(void){ int n; scanf("%d", &n); int coinValues[101]; for(int m = 0; m < 101; m++){ coinValues[m] = 0; } int *coins = (int *)malloc(sizeof(int) * n); for(int i = 0; i < n; i++){ scanf("%d", &coins[i]); coinValues[coins[i]]++; } int maximum = 0; for(int a = 1; a < 101; a++){ if(coinValues[a] > maximum){ maximum = coinValues[a]; } } printf("%d\n", maximum); return 0; }
#include<stdio.h> int main() { int i; int ara2[101]; for(i=0;i<101;i++){ ara2[i]=0; } int x; scanf("%d",&x); int ara[x]; for(i=0;i<x;i++){ scanf("%d",&ara[i]); ara2[ara[i]]++; } int highest; for(i=0;i<101;i++){ if(i==0) highest=ara2[0]; if(highest<ara2[i]) highest=ara2[i]; // printf("%d\n",ara2[i]); } printf("%d\n",highest); return 0; }
#include <stdio.h> int main(){ int i, j, cur_count, pre_count= 0, n; scanf("%i", &n); int arr_num[n]; for(i=0; i<n; ++i){ scanf("%i", &arr_num[i]); } for(i=0; i<n; ++i){ cur_count= 0; for(j=0; j<n; ++j){ if(arr_num[i]== arr_num[j]){ ++cur_count; } } if(cur_count> pre_count){ pre_count= cur_count; } } printf("%i", pre_count); }
#include <stdio.h> #include<limits.h> int max(int cnt[],int x) { int min=cnt[0]; for(int j=0;j<=100;j++) { if(cnt[j]>min) { min=cnt[j]; } } return min; } int main() { int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int cnt[101]={0}; for(int i=0;i<n;i++) { cnt[a[i]]++; } printf("%d",max(cnt,100)); return 0; }
#include <stdio.h> #define MaxN 120 #define for(i,a,b) for(int i=a; i<=b; i++) #define MAX(a,b) ((a) > (b) ? (a) : (b)) FILE *in, *out; //const char* fn_in = ""; //const char* fn_out = ""; int n, a[MaxN], x, mx; int main(){ mx=1; //freopen(fn_in, "r", stdin); //freopen(fn_out, "w", stdout); //printf(fn_out, "nhap du lieu"); scanf("%d", &n); for(i,1,n) { scanf("%d", &x); a[x]++; mx = MAX(mx, a[x]); } printf("%d", mx); }
#include <stdio.h> int main() { int sayi, i, j, most[101], deger[101], ans=0; scanf ("%d",&sayi); for (i=1;i<=100;i++) { most[i]=0; } for (i=1;i<=sayi;i++) { scanf ("%d",&deger[i]); } if (sayi==1) { printf ("1"); return 0; } for(i=1;i<=sayi;i++) { most[deger[i]]++; } for (i=1;i<=100;i++) { if ((most[i]>most[i+1]||most[i]>most[i-1])&&most[i]>ans) { ans=most[i]; } } if (ans==0) { printf ("1"); } else { printf ("%d",ans); } }
#include<stdio.h> int main() { int t,n[101],a,d[101],i,e,j; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&n[i]); } for(j=1;j<=100;j++) { d[j]=0; for(i=0;i<t;i++) { if(n[i]==j) { d[j]++; } } } e=d[1]; for(i=1;i<100;i++) { if(e>=d[i+1]) { continue; } else { e=d[i+1]; } } printf("%d",e); }
#include<stdio.h> #include<string.h> void sort(int x,int y,int z) { int i=0,j=0; } int main() { long long int ch[1000000]; char arr[100000]; int cp[4]= { 0,0,0,0 }; int a,b,c,d,e,g,i=0,tep=0,temp=0,j=0,k=0,l=0,m=0,n; scanf("%d",&a); //int m; l=0; m=0; for(i=0; i<a; i++) { scanf("%d",&ch[i]); l=i; j=1; while(l--) { if(ch[i]==ch[l]) j++; } if(m<j) m=j; } printf("%d",m); return 0; }
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
0
Edit dataset card