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

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

     1 #include <iostream>
     2 #include <fstream>
     3 #include <cstdlib>
     4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     5 using namespace std;
     6 
     7 ifstream fin("coin.in");
     8 ofstream fout("coin.out");
     9 
    10 int cnt_shu;
    11 long long he=0;
    12 
    13 int main(int argc, char** argv) {
    14 fin>>cnt_shu;
    15 int shi=0;
    16 for(int x=1;x<=cnt_shu;x+=shi){
    17  shi++;
    18  if(x+shi-1<=cnt_shu)he+=shi*shi;
    19  else he+=(cnt_shu-x+1)*shi;  
    20 }
    21 fout<<he;
    22 return 0;
    23 }

    第二题,同样很水

     1 #include <iostream>
     2 #include <fstream>
     3 #include <cstdlib>
     4 #include <string>
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 using namespace std;
     7 
     8 ifstream fin("mine.in");
     9 ofstream fout("mine.out");
    10 
    11 int cnt_hang=0,cnt_lie=0;
    12 int jv[105][105];
    13 int hez[8]={1,-1,0,0,1,-1,1,-1};
    14 int zoz[8]={0,0,1,-1,1,-1,-1,1};    
    15 
    16 int zhao(int he,int zo){
    17 
    18 int ans=0;
    19 for(int x=0;x<8;x++){
    20  int han=he+hez[x];
    21  int zon=zo+zoz[x];
    22  if(he<1||zo<1||he>cnt_hang||zo>cnt_lie)continue;
    23  if(jv[han][zon]==0)continue;
    24  else ans++;
    25 }
    26 return ans;
    27 }
    28 
    29 
    30 int main(int argc, char** argv) {
    31 fin>>cnt_hang>>cnt_lie;
    32 for(int x=1;x<=cnt_hang;x++){
    33  string a;fin>>a;
    34  for(int y=1;y<=cnt_lie;y++)if(a[y-1]=='*')jv[x][y]=1;    
    35 }
    36 for(int x=1;x<=cnt_hang;x++){
    37  for(int y=1;y<=cnt_lie;y++){
    38   if(jv[x][y]==0)fout<<zhao(x,y);    
    39   else fout<<"*";
    40  }    
    41  fout<<endl;
    42 }
    43 return 0;
    44 }

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

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

     1 #include <iostream>
     2 #include <fstream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 using namespace std;
     7 
     8 ifstream fin("sum.in");
     9 ofstream fout("sum.out");
    10 
    11 int cnt_ge,cnt_col=0;
    12 int id_num[100005];
    13 int head[100005],cnt=0;
    14 int zhan[3][100005];
    15 int zhan2[100005];
    16 long long ans;
    17 struct lian{
    18  int nxt;
    19  int to;    
    20 };
    21 lian cun[100005];
    22 
    23 void add(int sze,int yan);
    24 void sou(int yan);
    25 void suan_he(int ces);
    26 
    27 
    28 void add(int sze,int yan){
    29 cnt++;
    30 cun[cnt].to=sze;
    31 cun[cnt].nxt=head[yan];
    32 head[yan]=cnt;
    33 return;
    34 }
    35 
    36 
    37 int gs1=0,gs2=0;
    38 long long he1=0ll,he2=0ll;
    39 void sou(int yan){
    40 memset(zhan,0,sizeof(zhan));
    41 int sze=cun[head[yan]].to;
    42 gs1=0,gs2=0;
    43 he1=0ll,he2=0ll;
    44 for(int x=head[yan];x!=-1;x=cun[x].nxt){    
    45  int dao=cun[x].to;
    46  if((dao+sze)%2==0){
    47   he1+=dao;gs1++;
    48   zhan[0][gs1]=dao;    
    49  }
    50  else{
    51   he2+=dao;gs2++;
    52   zhan[1][gs2]=dao;    
    53  }     
    54 }
    55 
    56 for(int x=0;x<2;x++)suan_he(x);    
    57 return;
    58 }
    59 
    60 
    61 void suan_he(int ces){
    62 int gs=0;long long he=0ll;
    63 if(ces==0){gs=gs1;he=he1;}     
    64 else {gs=gs2;he=he2;}
    65 if(gs==0||gs==1)return;
    66 int shu=0;
    67 for(int x=gs;x>=1;x--){
    68  shu=((he+zhan[ces][x])/2*id_num[zhan[ces][x]])*10007;
    69  ans+=shu*2%10007;
    70  ans*=10007;
    71 }
    72 
    73 return;
    74 }
    75 
    76 
    77 int main(int argc, char** argv) {
    78 fin>>cnt_ge>>cnt_col;
    79 memset(head,-1,sizeof(head));
    80 for(int x=1;x<=cnt_ge;x++)fin>>id_num[x];    
    81 for(int x=1;x<=cnt_ge;x++){
    82 int yan;fin>>yan;
    83 add(x,yan);    
    84 }
    85 for(int x=1;x<=cnt_col;x++){
    86  sou(x);    
    87 }
    88 fout<<ans%10007;
    89 return 0;
    90 }

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

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

     1 #include <iostream>
     2 #include <fstream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 using namespace std;
     7 
     8 ifstream fin("salesman.in");
     9 ofstream fout("salesman.out");
    10 
    11 int cnt_shu;
    12 int jv[100005];
    13 int a[100005];
    14 int ans[100005];
    15 int shang[100005];
    16 int hou[100005];
    17 int gs=0;
    18 int dui[100005];
    19 int wei;
    20 void pout(int sze);
    21 void zhuan( );
    22 void na(int sze);
    23 
    24 void pout(int sze){
    25  gs++;dui[gs]=sze;
    26  int now=gs,fu;    
    27  while(now/2>0){
    28  fu=now/2; 
    29  if(a[dui[fu]]<a[dui[now]])return;    
    30  int b=dui[fu];dui[fu]=dui[now];dui[now]=b;
    31  now=fu;
    32  }
    33  return;
    34 }
    35 
    36 void zhuan( ){
    37 for(int x=2;x<=cnt_shu;x++)shang[x]=x-1;
    38 for(int x=1;x<cnt_shu;x++)hou[x]=x+1;
    39 for(int x=1;x<cnt_shu;x++){
    40  int dai1=a[dui[1]];
    41  int dai2=(jv[wei]-jv[shang[wei]])*2+a[wei];
    42  if(dai1>=dai2){
    43   ans[cnt_shu-x]=ans[cnt_shu-x+1]-dai2;
    44   wei=shang[wei]; na(wei);
    45  }     
    46  else{
    47   hou[shang[dui[1]]]=hou[dui[1]];
    48   shang[hou[dui[1]]]=shang[dui[1]];
    49   na(1);
    50   ans[cnt_shu-x]=ans[cnt_shu-x+1]-dai1;    
    51    
    52 }
    53  }
    54 return;    
    55 }
    56 
    57 
    58 void na(int sze){
    59 dui[sze]=dui[gs];
    60 gs--;    
    61 int now=sze,zi=0;
    62 while(now*2<=gs){
    63  zi=now*2;
    64  if(a[dui[zi+1]]<a[dui[zi]]&&now*2<gs)zi++;
    65  if(a[dui[zi]]>a[dui[now]])return;
    66  int b=dui[zi];dui[zi]=dui[now];
    67  dui[now]=b;now=zi;
    68 }
    69 return;
    70 }
    71 
    72 
    73 int main(int argc, char** argv) {
    74 fin>>cnt_shu;
    75 for(int x=1;x<=cnt_shu;x++){
    76 fin>>jv[x];ans[cnt_shu]=jv[x]*2;    
    77 }
    78 for(int x=1;x<=cnt_shu;x++){
    79 fin>>a[x];
    80 if(x!=cnt_shu)pout(x);
    81 ans[cnt_shu]+=a[x];
    82 }
    83 wei=cnt_shu;
    84 zhuan( );
    85 for(int x=1;x<=cnt_shu;x++)fout<<ans[x]<<endl;
    86 
    87  return 0;
    88 }
  • 相关阅读:
    浅析嵌入式程序设计中的优化问题
    TCP粘包问题
    使用python 批量 配对t检验 医学 基础研究 数据分析
    Ubuntu误删系统文件修复办法
    飞思卡尔powerpc交叉编译环境的
    ubuntu packege下载网址
    数组对象里面对日期进行排序
    c# 字符串以逗号分割属性加上单引号
    Vue mysql 变量赋值, 获取数组
    Element vue Select 下拉框默认
  • 原文地址:https://www.cnblogs.com/Ateisti/p/5053425.html
Copyright © 2011-2022 走看看