多比特杯武汉工程大学第四届ACM程序设计竞赛-代码记录

A.倍速播放—模拟

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
signed main()
{
    char t[25],s[25];
    double chu,tt;
    int a,b,c,sum,len;
    while(scanf("%s",t)!=EOF)
	{
        for(int i=0;i<8;i++)s[i]='0';
        len = strlen(t);
        scanf("%lfx",&chu);
        for(int i=8-len,j=0;i<8;i++,j++)s[i]=t[j];
        
        a=(s[0]-'0')*10+s[1]-'0';
        b=(s[3]-'0')*10+s[4]-'0';
        c=(s[6]-'0')*10+s[7]-'0';
        sum=a*3600+b*60+c;
        
        tt=(double)1.0*(double)sum / (1.0*chu) + 0.500001;
        
        sum=tt;
        a=sum/3600;sum%=3600;
        b=sum/60;sum%=60;
        c=sum;
        sum=tt;
        if(sum<60)printf("0:%02d\n",c);
        else if(sum>=60&&sum<3600)printf("%d:%02d\n",b,c);
        else if(sum>=3600)printf("%d:%02d:%02d\n",a,b,c);
	}
}

B.阶乘求导—简单推导

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1000010,mod = 1e9+7;
const double y=0.57721566490153286060651209008240243104215933593992;
double s[N];
signed main()
{
    s[1]=-y;
    for(int i=2;i<N;i++)
    {
    	double t=1.0/((double)1.0*(i-1));
    	s[i]=s[i-1]+t;
	}
    int T,x;scanf("%d",&T);
    while(T--)
    {
    	scanf("%d",&x);
    	printf("%.6lf\n",s[x]);
	}
	
}

D.逃离符联网—二分+dfs

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
#define int long long
const int N = 620,mod = 1e9+7;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int g[N][N];
int n,m;
int x,y,w,z;
bool vis[N][N];

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>g[i][j];
    cin>>x>>y>>w>>z;
    x--,y--,w--,z--;
    
    function<bool(int,int,int)> dfs = [&](int x,int y,int maxd)
    {
          vis[x][y]=true;
          if(x==w&&y==z)return true;
          for(int i=0;i<4;i++)
          {
              int a=x+dx[i],b=y+dy[i];
              if(a<0||a>=n||b<0||b>=m||vis[a][b]||g[a][b]>maxd)continue;
              if(dfs(a,b,maxd))return true;
          }
          return false;
    };
    int l=g[x][y],r=1e9;
    while(l<r)
    {
        int mid=l+r>>1;
        memset(vis,0,sizeof vis);
        if(dfs(x,y,mid))r=mid;
        else l=mid+1;
    }
    cout<<r<<'\n';
   
}

E.讨厌的字符串—思维推理

#include<iostream>
using namespace std;
signed main()
{
    int n;cin>>n;
    if(n>3)cout<<"YES"<<'\n';
    else cout<<"NO"<<'\n';
}

G.带黄狗的礼物—线性求逆元+组合数

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod = 1e9+7,N = 1e7+10;
#define int long long
int inv[N];
signed main(){
    int n,m;
    cin>>n>>m;
    
    inv[0]=inv[1]=1;
	for(int i=2;i<N;i++)inv[i]=((mod-mod/i)*inv[mod%i])%mod;
    
    int res=1;
    for(int i=1;i<=m+n-1;i++)res=(res*i)%mod;
    for(int i=1;i<=n-1;i++)res=(res*inv[i])%mod;
    for(int i=1;i<=m;i++)res=(res*inv[i])%mod;
    cout<<res<<endl;
}

I.自习室的灯—打表找规律

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define int long long
signed main()
{
	int n;
	cin>>n;
	vector<int>res;
	for(int i=1,t=2;i<=n;)
	{
		res.push_back(i);
		i+=t+1;
		t+=2;
	}
	cout<<res.size();
	for(auto x : res)cout<<" "<<x;
	cout<<'\n';
}

J.攻击力进阶测试—二分+树状数组

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
const int N = 200010,mod = 1e9+7;
int d[N],tr[N];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int v)
{
    for(int i=x;i<N;i+=lowbit(i))tr[i]+=v;
}
int query(int x)
{
    int res=0;
    for(int i=x;i>=1;i-=lowbit(i))res+=tr[i];
    return res;
}
void solve()
{
    int n;cin>>n;
    memset(tr,0,sizeof(int)*(n+1));
    for(int i=1;i<=n;i++)cin>>d[i],add(i,d[i]);
    int q;cin>>q;
    while(q--)
    {
        int t;cin>>t;
        if(t==1)
        {
            int p,dd;cin>>p>>dd;
            add(p,dd-d[p]);
            d[p]=dd;
        }
        else
        {
            int m;cin>>m;
            int l=0,r=n;
            while(l<r)
            {
                int mid=l+r+1>>1;
                if(query(mid)<=m)l=mid;
                else r=mid-1;
            }
            cout<<r<<" "<<(query(n)+m-1)/m<<'\n';
        }
    }
}
signed main()
{
    int T;cin>>T;
    while(T--)solve();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_WAWA鱼_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值