Only 3 dishes. . TUT. .
Question A: Calculating Function
Water. Each two items is 1. Discuss the classification of parity.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int main(){ LL n, x; scanf("%I64d",&n); x=n/2; if(n&1) printf("%I64d\n",x-n); else printf("%I64d\n",x); return 0;}
Water.
Fill in the ones that must be 0, and then determine whether the ones that are 1 meet the conditions. If it matches, output all the remaining ones as 1, if not, output no.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int a[110][110], b[110][110];int main(){ int i, j, k, n, m, flag, flag1, flag2; scanf("%d%d",&n,&m); for(i=0; i<n; i++) { for(j=0; j<m; j++) { scanf("%d",&b[i][j]); } } flag=0; memset(a,0,sizeof(a)); for(i=0; i<n; i++) { for(j=0; j<m; j++) { if(!b[i][j]) { for(k=0; k<n; k++) { a[k][j]=1; } for(k=0; k<m; k++) { a[i][k]=1; } } } } for(i=0; i<n; i++) { for(j=0; j<m; j++) { if(b[i][j]) { flag1=flag2=0; for(k=0;k<n;k++) { if(!a[k][j]) { flag1=1; break; } } for(k=0;k<m;k++) { if(!a[i][k]) { flag2=1; break; } } if(!flag1&&!flag2) flag=1; } } } if(flag) puts("NO"); else { puts("YES"); for(i=0; i<n; i++) { for(j=0; j<m; j++) { printf("%d ",1-a[i][j]); } puts(""); } } return 0;}
First find out the number of steps required to change letters, only where P is located That half changes.
Then find the number of smaller moves. Just add up.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;char s[110000];int judge(char c1, char c2){ int x; if(c1>c2) swap(c1,c2); return min(c2-c1,c1+26-c2);}int main(){ int l, r, len, i, p, sum=0, flag=0; scanf("%d%d",&len,&p); p--; l=len-1; r=0; scanf("%s",s); for(i=0; i<len/2; i++) { if(s[i]!=s[len-i-1]) { sum+=judge(s[i],s[len-i-1]); if(p<len/2) { l=min(l,i); r=max(r,i); } else { l=min(l,len-i-1); r=max(r,len-i-1); } flag=1; } } if(!flag) puts("0"); else { if(p-l>r-p) { sum+=r-l+abs(r-p); } else { sum+=r-l+abs(p-l); } printf("%d\n",sum); } return 0;}