[NOIP2015pj题解]From某因为时间快了那么一点点超过下一位的蒟蒻(其实是纯代码).

第一题,很水,直接上代码

 #include <iostream>
#include <fstream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std; ifstream fin("coin.in");
ofstream fout("coin.out"); int cnt_shu;
long long he=; int main(int argc, char** argv) {
fin>>cnt_shu;
int shi=;
for(int x=;x<=cnt_shu;x+=shi){
shi++;
if(x+shi-<=cnt_shu)he+=shi*shi;
else he+=(cnt_shu-x+)*shi;
}
fout<<he;
return ;
}

第二题,同样很水

 #include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std; ifstream fin("mine.in");
ofstream fout("mine.out"); int cnt_hang=,cnt_lie=;
int jv[][];
int hez[]={,-,,,,-,,-};
int zoz[]={,,,-,,-,-,}; int zhao(int he,int zo){ int ans=;
for(int x=;x<;x++){
int han=he+hez[x];
int zon=zo+zoz[x];
if(he<||zo<||he>cnt_hang||zo>cnt_lie)continue;
if(jv[han][zon]==)continue;
else ans++;
}
return ans;
} int main(int argc, char** argv) {
fin>>cnt_hang>>cnt_lie;
for(int x=;x<=cnt_hang;x++){
string a;fin>>a;
for(int y=;y<=cnt_lie;y++)if(a[y-]=='*')jv[x][y]=;
}
for(int x=;x<=cnt_hang;x++){
for(int y=;y<=cnt_lie;y++){
if(jv[x][y]==)fout<<zhao(x,y);
else fout<<"*";
}
fout<<endl;
}
return ;
}

第三题本来信心满满以为可以过,结果学军的数据测出来知过了2组,本以为没有希望了,结果官方测出是60分,还有40分是因为最后一步作死的没有mod,233.

我是找了规律才勉强将官方数据A过,学军的,真心做不到.

 #include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std; ifstream fin("sum.in");
ofstream fout("sum.out"); int cnt_ge,cnt_col=;
int id_num[];
int head[],cnt=;
int zhan[][];
int zhan2[];
long long ans;
struct lian{
int nxt;
int to;
};
lian cun[]; void add(int sze,int yan);
void sou(int yan);
void suan_he(int ces); void add(int sze,int yan){
cnt++;
cun[cnt].to=sze;
cun[cnt].nxt=head[yan];
head[yan]=cnt;
return;
} int gs1=,gs2=;
long long he1=0ll,he2=0ll;
void sou(int yan){
memset(zhan,,sizeof(zhan));
int sze=cun[head[yan]].to;
gs1=,gs2=;
he1=0ll,he2=0ll;
for(int x=head[yan];x!=-;x=cun[x].nxt){
int dao=cun[x].to;
if((dao+sze)%==){
he1+=dao;gs1++;
zhan[][gs1]=dao;
}
else{
he2+=dao;gs2++;
zhan[][gs2]=dao;
}
} for(int x=;x<;x++)suan_he(x);
return;
} void suan_he(int ces){
int gs=;long long he=0ll;
if(ces==){gs=gs1;he=he1;}
else {gs=gs2;he=he2;}
if(gs==||gs==)return;
int shu=;
for(int x=gs;x>=;x--){
shu=((he+zhan[ces][x])/*id_num[zhan[ces][x]])*;
ans+=shu*%;
ans*=;
} return;
} int main(int argc, char** argv) {
fin>>cnt_ge>>cnt_col;
memset(head,-,sizeof(head));
for(int x=;x<=cnt_ge;x++)fin>>id_num[x];
for(int x=;x<=cnt_ge;x++){
int yan;fin>>yan;
add(x,yan);
}
for(int x=;x<=cnt_col;x++){
sou(x);
}
fout<<ans%;
return ;
}

第四题,我到现在为止都不知道它为什么学军的数据A过,官方数据A过,在我心中,这种算法本身就是错误的,我是想将选所有人的情况

都算出来,然后再一个一个减的(用了传说中的优先队列),怎么对的完,是数据太弱了,还是我运气太好了,还是说我的方法本身就是正确的???

 #include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std; ifstream fin("salesman.in");
ofstream fout("salesman.out"); int cnt_shu;
int jv[];
int a[];
int ans[];
int shang[];
int hou[];
int gs=;
int dui[];
int wei;
void pout(int sze);
void zhuan( );
void na(int sze); void pout(int sze){
gs++;dui[gs]=sze;
int now=gs,fu;
while(now/>){
fu=now/;
if(a[dui[fu]]<a[dui[now]])return;
int b=dui[fu];dui[fu]=dui[now];dui[now]=b;
now=fu;
}
return;
} void zhuan( ){
for(int x=;x<=cnt_shu;x++)shang[x]=x-;
for(int x=;x<cnt_shu;x++)hou[x]=x+;
for(int x=;x<cnt_shu;x++){
int dai1=a[dui[]];
int dai2=(jv[wei]-jv[shang[wei]])*+a[wei];
if(dai1>=dai2){
ans[cnt_shu-x]=ans[cnt_shu-x+]-dai2;
wei=shang[wei]; na(wei);
}
else{
hou[shang[dui[]]]=hou[dui[]];
shang[hou[dui[]]]=shang[dui[]];
na();
ans[cnt_shu-x]=ans[cnt_shu-x+]-dai1; }
}
return;
} void na(int sze){
dui[sze]=dui[gs];
gs--;
int now=sze,zi=;
while(now*<=gs){
zi=now*;
if(a[dui[zi+]]<a[dui[zi]]&&now*<gs)zi++;
if(a[dui[zi]]>a[dui[now]])return;
int b=dui[zi];dui[zi]=dui[now];
dui[now]=b;now=zi;
}
return;
} int main(int argc, char** argv) {
fin>>cnt_shu;
for(int x=;x<=cnt_shu;x++){
fin>>jv[x];ans[cnt_shu]=jv[x]*;
}
for(int x=;x<=cnt_shu;x++){
fin>>a[x];
if(x!=cnt_shu)pout(x);
ans[cnt_shu]+=a[x];
}
wei=cnt_shu;
zhuan( );
for(int x=;x<=cnt_shu;x++)fout<<ans[x]<<endl; return ;
}
上一篇:ibatis2.3中#和$符号的区别(转)


下一篇:[转]MySQL 清空慢查询文件