# 2011 Heilongjiang collegiate programming contest 【(7+1)/10】 [补完]

[CDOJ] https://vjudge.net/contest/170394#overview
[hrbust1395~1402(中文题面哦!) ] http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblemVolume

# A UESTC 924 Alphabet Cookies

—————————————————————————————————————————

# B UESTC 925 Sequential game

—————————————————————————————————————————

# C UESTC 926 Programming Contest Ranking

—————————————————————————————————————————

#include <bits/stdc++.h>
using namespace std;
const int N = 222;
/*********************************************/
int n,m;
struct node {
char name[22];
int ac,total,weight;
bool st[22];
int att[22];
}p[N];

int blood[N];
int aa[N];

char s[100];
void input(){
vector<int>v[N];

for(int i=1;i<=m;i++) blood[i]=333,aa[i]=0;

for(int i=1;i<=n;i++){
p[i].total=p[i].weight=p[i].ac=0;
scanf("%s",p[i].name);
for(int j=1;j<=m;j++){
scanf("%s",s);
int l = strlen(s);
if(s[l-1]=='-') {
p[i].st[j]=0;
continue;
}

int &x = p[i].att[j],flag=0,y=0;
x=0;
for(int k=0;s[k];k++){
if(s[k]=='\\'){
flag=1;
continue;
}
if(!flag) x=x*10+s[k]-'0';
else      y=y*10+s[k]-'0';
}
p[i].ac++;
p[i].total+=y+x*20-20;
p[i].st[j]=1;
aa[j]++;
if(blood[j]>y){
blood[j]=y;
v[j].clear();
v[j].push_back(i);
}
else if(blood[j]==y){
v[j].push_back(i);
}
}
}

for(int i=1;i<=m;i++)  if(aa[i]) aa[i]=n/aa[i];

for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
p[i].weight+=p[i].st[j]*aa[j];

for(int j=1;j<=m;j++){
if(blood[j]==333) continue;
for(int i=0;i<v[j].size();i++)
p[v[j][i]].total-=p[v[j][i]].att[j]*20-20;
}
}

bool cmp(node a,node b){
if(a.ac==b.ac){
if(a.total==b.total){
if(a.weight==b.weight)
return strcmp(a.name,b.name)<0;
return a.weight>b.weight;
}
return a.total<b.total;
}
return a.ac>b.ac;
}

int rk[N];
int main(){
while(~scanf("%d%d",&n,&m)){
input();
sort(p+1,p+n+1,cmp);
rk[1]=1;

for(int i=1;i<=n;i++){
if(i>1){
if(p[i].ac     == p[i-1].ac&&
p[i].total  == p[i-1].total&&
p[i].weight == p[i-1].weight){
rk[i]=rk[i-1];
}
else rk[i]=i;
}
printf("%*d %*s %*d %*d %*d\n",3,rk[i],20,p[i].name,2,p[i].ac,6,p[i].total,4,p[i].weight);
}
}
return 0;
}

# D UESTC 927 Dart game

—————————————————————————————————————————

dp1[0]=1;
for(int i=0;i<v.size();i++)
for(int j=1;j<N;j++)
if(j-v[i]>=0)  dp1[j]=(dp1[j]+dp1[j-v[i]])%MOD;

#include <bits/stdc++.h>

typedef long long int LL;

using namespace std;

const int N   = 1111;
const int MOD = 2011;

/*********************************************/

int dp1[N],dp2[N],ans[N];

void init(){
memset(dp1,0,sizeof(dp1));
memset(dp2,0,sizeof(dp2));

vector<int>v;
v.push_back(25),v.push_back(50);
for(int i=1;i<=20;i++){
v.push_back(i);
v.push_back(i*2);
v.push_back(i*3);
}

sort(v.begin(),v.end());

dp1[0]=1;
for(int i=0;i<v.size();i++)
for(int j=1;j<N;j++)
if(j-v[i]>=0)  dp1[j]=(dp1[j]+dp1[j-v[i]])%MOD;

v.clear();
v.push_back(25);
for(int i=1;i<=20;i++){
v.push_back(i);
v.push_back(i*3);
}

sort(v.begin(),v.end());

dp2[0]=1;
for(int i=0;i<v.size();i++)
for(int j=1;j<N;j++)
if(j-v[i]>=0)  dp2[j]=(dp2[j]+dp2[j-v[i]])%MOD;

for(int i=1;i<N;i++) ans[i]=(dp1[i]-dp2[i]+MOD)%MOD;
}

int main(){
init();int n;
while(~scanf("%d",&n)&&n) printf("%d\n",ans[n]);
return 0;
}

# E UESTC 928 Similar Word

—————————————————————————————————————————

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char a[150000];
char bb[150000];
int n;
int minRepresentation(char b[])
{
int l=n;
int i = 0, j = 1, k = 0, t;
while(i < l && j < l && k < l) {
t = b[(i + k) >= l ? i + k - l : i + k] - b[(j + k) >= l ? j + k - l : j + k];
if(!t) k++;
else{
if(t > 0) i = i + k + 1;
else j = j + k + 1;
if(i == j) ++ j;
k = 0;
}
}
return (i < j ? i : j);
}
int main()
{
while(~scanf("%s%s",a,bb))
{
if(strcmp(a,bb)==0)
{
printf("no\n");
continue;
}
if(strlen(a)!=strlen(bb))
{
printf("no\n");
continue;
}
int flag=0;
n=strlen(a);
int posa=minRepresentation(a);
int posb=minRepresentation(bb);
for(int i=0;i<n;i++)
{
if(a[posa]!=bb[posb])flag=1;
posa++;
posb++;
posa%=n;
posb%=n;
}
if(flag==0)
printf("yes\n");
else printf("no\n");
}
}

# F UESTC 929 Post office

—————————————————————————————————————————

….

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int n;
ll sum[150000];
ll a[150000];
int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)scanf("%lld",&a[i]);
for(int i=0;i<n;i++)
{
if(i==0)sum[i]=a[i];
else sum[i]=sum[i-1]+a[i];
}
int q;
scanf("%d",&q);
while(q--)
{
int x,y;
scanf("%d%d",&x,&y);
x--;
y--;
if((y-x+1)%2==1)
{
int mid=(x+y)/2;
ll num=(y-x+1)/2;
ll output=a[mid]*num-(sum[mid-1]-sum[x-1]);
output+=(sum[y]-sum[mid])-a[mid]*num;
printf("%lld\n",output);
}
else
{
int mid=(x+y)/2;
ll num=(y-x+1)/2-1;
ll output=a[mid]*num-(sum[mid-1]-sum[x-1]);
output+=(sum[y]-sum[mid])-a[mid]*(num+1);
mid=(x+y)/2+1;
num=(y-x+1)/2;

ll output2=a[mid]*num-(sum[mid-1]-sum[x-1]);
output2+=(sum[y]-sum[mid])-a[mid]*(num-1);
printf("%lld\n",min(output,output2));
}
}
}
}

# G UESTC 930 Lucky Boy

—————————————————————————————————————————

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

const int N = 10000 +7;

map<int,map<int,int> >mmp;

int x[N],y[N];

int main() {
int n;
while(~scanf("%d",&n)) {
for(int i=1; i<=n; i++)           scanf("%d%d",&x[i],&y[i]);

int flag = 0,xx,yy,t; // equal;
for(int i=1; i<=n; i++) {
mmp.clear();
for(int j=1; j<=n; j++) {
if(i==j) continue;
if(x[i]==x[j]&&y[i]==y[j]) flag=1;
xx=x[i]-x[j];
yy=y[i]-y[j];
if(xx<0) xx*=-1,yy*=-1;
t=__gcd(xx,yy);
xx/=t,yy/=t;
if(mmp[xx][yy]) flag=1;
mmp[xx][yy]=1;
}
}
if(flag ) {
printf("a");
} else {
if(n%(3)==0) printf("b");
else         printf("a");
}
puts(" is the lucky boy.");
}
return 0;
}

# H UESTC 931 Car race game

—————————————————————————————————————————
XianGe非常喜欢赛车比赛尤其是像达喀尔拉力赛，这种的比赛规模很大，涉及到很多国家的车队的许多车手参赛。XianGe也梦想着自己能举办一个这样大规模的比赛，XianGe幻想着有许多人参赛，那是人山人海啊，不过XianGe只允许最多100000人参加比赛。

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

const int N = 1000000 +7;

struct node{
int x,v;
}a[N];

bool cmp(node a,node b){
if(a.x==b.x) return a.v<b.v;
return a.x>b.x;
}

int sum[N];
#define lowbit(x) (x&-x)
void update(int i,int v){
for(;i<N;i+=lowbit(i)) sum[i]+=v;
}
int getSum(int i){
int ans = 0; for(;i;i-=lowbit(i)) ans+=sum[i];
return ans;
}

int main(){
int n;
while(~scanf("%d",&n)){
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].v);

sort(a+1,a+n+1,cmp);
LL mx = 0;
for(int i=1;i<=n;i++){
mx += getSum(a[i].v-1);
update(a[i].v,1);
}

printf("%lld\n",mx);
}
return 0;
}

# I UESTC 932 Jiulianhuan

—————————————————————————————————————————

1第一个环可以在任何时候挂到柄上或者从柄上摘下
2在任何时候，你只能操作一个环
3如果前k-2个环都没有在柄上，并且第k-1个环在柄上，这时如果第k个环在柄上的话，可以把它摘下来，如果它不在柄上，可以把它挂上去

0000011
1111100(长度为n)

f[i]=f[i2]+2i1f[1]=1f[2]=2

[f[i+2]f[i+1]f[i]2i+2]×0101100001000002=[f[i+3]f[i+2]f[i+1]2i+3] $\left[\begin{array}{cc} f[i+2]&&f[i+1]&&f[i]&&2^{i+2} \end{array}\right]\times \left[\begin{array}{cc} 0&&1&&0&&0 \\1&&0&&1&&0 \\0&&0&&0&&0 \\1&&0&&0 &&2 \end{array}\right] = \left[\begin{array}{cc}f[i+3]&&f[i+2]&&f[i+1]&&2^{i+3}\end{array}\right]$

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
const int N = 222;
const int MOD = 10007;
/*********************************************/
const int M = 4;

struct Matrix{
LL m[M][M];
void clear0(){
for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
m[i][j]=0;
}
void clearE(){
for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
m[i][j]=(i==j);
}
};

Matrix operator * (Matrix &a,Matrix &b){
Matrix c;c.clear0();

for(int k=0;k<M;k++)
for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j]+MOD)%MOD;
return c;
}

Matrix operator ^ (Matrix &a,LL b){
Matrix c;c.clearE();
while(b){
if(b&1)  c=c*a;
b>>=1,a=a*a;
}
return c;
}

int main(){
int n;
while(~scanf("%d",&n)){
Matrix a,b;
a.clear0(),b.clear0();

a.m[0][0]=5;
a.m[0][1]=2;
a.m[0][2]=1;
a.m[0][3]=8;

b.m[0][1]=1;
b.m[1][0]=b.m[1][2]=1;
b.m[3][0]=1,b.m[3][3]=2;

b=b^(n-1);
a=a*b;

printf("%lld\n",a.m[0][2]);
}
return 0;
}

# J UESTC 933 The minimum square sum

—————————————————————————————————————————

#include <bits/stdc++.h>

typedef long long int LL;

using namespace std;

int main(){
LL n;
while(~scanf("%lld",&n)){
LL mi = n*n+n*n;
for(LL i=1;i*i<n;i++){
LL t = n-i*i;
LL tt = sqrt(t+1.0);
if(t == tt*tt){
mi = n;
break;
}
}
printf("%lld\n",mi);
}
return 0;
}

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
int main() {
LL n;
while(~scanf("%lld",&n)) {
if(n%4==3) printf("%lld\n",n*n*2);
else       printf("%d\n",n);
}
return 0;
}
07-14 357

07-30 161