Codeforces 622

来源:互联网 发布:千里眼远程监控软件 编辑:程序博客网 时间:2024/06/06 14:09

http://codeforces.com/problemset/problem/622/A
这题必须得mark一下,就是由于自己的马虎,没有算一下数组,导致数组开小了,致使不出结果,runtimeerro,还wrong了一发,直接用乘法表达式的形式也可以

#include<bits/stdc++.h>using namespace std;#define ll long longconst int maxn=2e7+10;ll n;ll a[maxn];ll sum=0;int main(){    int count=0;cin>>n;    for(int i=1;i<2e7+5;i++){        a[i]=a[i-1]+i;sum=a[i];    }       int pos;    for(int i=1;;i++){        if(a[i]>n){            pos=i;break;        }    }    ll ans=n-a[pos-1];    if(ans==0) ans=pos-1;    cout<<ans<<endl;}

http://codeforces.com/problemset/problem/622/B
这题可以暴力也可以O(1),就是记录一下方法,这种题可以暴力,恩恩,然后根据表达式的话可以先算出现有时间表示成分,加上分钟后再转换回去

#include<bits/stdc++.h>using namespace std;#define ll long longchar s[105];int t;int main(){    cin>>s>>t;    int h=(s[0]-'0')*10+s[1]-'0';    int m=(s[3]-'0')*10+s[4]-'0';    int dt=(t+m)/60;int dm=(t)%60;    h=(h+dt)%24;m=(m+dm)%60;    if(h<10) cout<<"0";    cout<<h<<":";    if(m<10) cout<<"0";    cout<<m<<endl;}

http://codeforces.com/problemset/problem/622/D

构造一个排列,使得表达式值最小,通过乘积形式可以想到使两边都为0,构造答案为0。

#include<bits/stdc++.h>using namespace std;int n;const int maxn=1e6+110;int a[maxn];int main(){    cin>>n;    //if(n%2==1){        int kk=1;        for(int i=1;i<=n+1-i;i++){            a[i]=a[n+1-i]=kk;kk+=2;        }        kk=2;        for(int i=1;n+i<=2*n-i;i++){            a[n+i]=a[2*n-i]=kk;kk+=2;        }        a[0]=n;        for(int i=0;i<2*n;i++){            printf("%d ",a[i]);        }    //}}
1 0
原创粉丝点击