5.30题解

5.30题解

第一题
在这里插入图片描述

第一天1x1,第二天2x2,累加到n跳出循环,数据很小也不用多想直接输出。

#include<bits/stdc++.h>
using namespace std;
int n,sum;
long long ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			ans+=i;
			sum++;
			if(sum==n) break;
		}
		if(sum==n) break;
	}
	cout<<ans;
} 

第二题
在这里插入图片描述

广搜模板,8个方向建个数组搜索,如果3*3内有炸弹就加1。很久没有打了忘记搜了一个要标记,一直没结果,浪费很多时间。

#include<bits/stdc++.h>
using namespace std;
int next[8][2]{{1,1},{-1,-1},{1,-1},{-1,1},{0,1},{1,0},{0,-1},{-1,0}};
char a[1000][1000],b[1000][1000];
bool dis[1000][1000];
int n,m;
void dfs(int x,int y){
	if(a[x][y]=='*') b[x][y]=a[x][y];
	if(x>n || y>m || x<0 || y<0 || dis[x][y]==1) return;
	for(int i=0;i<8;i++){
	    int fx=x;int fy=y;
		dis[fx][fy]=1;
		fx+=next[i][0];
		fy+=next[i][1];
		dfs(fx,fy);
		if(a[fx][fy]=='*' && a[x][y]!='*') {
			if(!b[x][y]) b[x][y]='1';
			else b[x][y]++;
	}
	
}}
int main(){
	//freopen("mine.in","r",stdin);
	//freopen("mine.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}	
	dfs(0,0);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(b[i][j])cout<<b[i][j];
			else cout<<"0";
		}
		cout<<endl;
	}
}

第三题
在这里插入图片描述
这个题感觉是最难的一道。
先看第一个条件 x+z=2y,得出x+z为偶数,即x,z奇偶性质相同
再看第二个性质
(x+z)
(num[x]+num[z])=xnum[x]+xnum[z]+znum[x]+znum[z]
又因为x,z奇偶性质相同
所以可以化简为(i1num[i1]+i1num[i2]+i2num[i1]+i2num[i3])+(i1num[i1]+i1num[i3]+i3num[i1]+i3num[i3])…
再提出i1相同项,得到
i1*(num[i1]+num[i2]+…….+num[in])+n*(i1num[i1])
对于in
则是in
(num[i1]+num[i2]+…….+num[in])+n*(in*num[in])
再求和就是答案。

#include<bits/stdc++.h>
using namespace std;
int n,c;
int sum[2][100001],num[100001],d[2][100001];
int col[100001];
long long maxx;
int main()
{
    cin>>n>>c;
    for (int i=1;i<=n;i++)
    {
        cin>>num[i];
        num[i]%=10007;    
    }
    for (int i=1;i<=n;i++)
    {
        cin>>col[i];
        sum[i%2][col[i]]+=num[i];    
        sum[i%2][col[i]]%=10007;
        d[i%2][col[i]]++;        
    }
    for (int i=1;i<=n;i++)
    {
        maxx+=i%10007*((sum[i%2][col[i]]+(d[i%2][col[i]]-2)%10007*num[i])%10007);
        maxx%=10007;        
    }
    cout<<maxx;
    return 0;
}

第四题
在这里插入图片描述

我本来是准备直接混点分的,没想到还能ac。代码只适用于每次的第一个用户不变的情况,也就是疲劳值的最大值小于最大路程的两倍的情况,如果存在有一个用户的推销疲劳值极大就不对了。

#include<bits/stdc++.h>
using namespace std;
int dp[100001],a[100001],b[10001],n,t,st,k,flag;
int main(){
	//freopen("salesman.in","r",stdin);
	//freopen("salesman.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=1;i<=n;i++){
		if(dp[1]<2*a[i]+b[i]){
			dp[1]=2*a[i]+b[i];
			st=i;
		}
	}
	dp[n]+=b[st];
	b[st]=0;
	sort(b+1,b+1+n);
	cout<<dp[1]<<endl;
	for(int i=2;i<=n-1;i++){
		dp[i]=dp[i-1];
		dp[i]+=b[n-(k++)];
		cout<<dp[i]<<endl;
	}
	for(int i=1;i<=n;i++){
		dp[n]+=b[i];
	}
	cout<<dp[n]+2*a[n]<<endl;
}

正确代码应该是
我们先把数组排序
用sum[i]表示a数组的前i项的和,q[i]表示s数组的前i项的最大值,h[i]表示a[i]2+s[i]后i项的最大值,对于每个x,他的答案就是max(sum[x]+2q[x],sum[x-1]+h[x])

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct home{
    int s,v;
}a[100010];
int q[100010];
int h[100010],qm[100010];
int n;
bool cmp(home a,home b)
{
    return a.v>b.v;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].s);
    }
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].v);
    }
    sort(a+1,a+1+n,cmp);
    for (int i=n;i>=1;i--)
    {
        h[i]=max(h[i+1],2*a[i].s+a[i].v);
    }
    for (int i=1;i<=n;i++)
    {
        qm[i]=max(qm[i-1],a[i].s);
    }
    for (int i=1;i<=n;i++)
        q[i]=q[i-1]+a[i].v;
    for (int i=1;i<=n;i++)
    {
        printf("%d\n",max(q[i-1]+h[i],q[i]+2*qm[i]));
    }
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Using: Intel (R) PRO Network Connections SDK v2.30.10 EEUPDATE v5.30.10.00 Copyright (C) 1995 - 2017 Intel Corporation Intel (R) Confidential and not for general distribution. ----------------------------------------------------- Options: /HELP or /? Displays command line help. /EXITCODES Displays exit code help. /ALL Selects all adapters found in the system. /NIC=XX Selects a specific adapter (1-32). /BUS=XX Selects PCI bus of adapter to program. Must be used with the DEV parameter to specify an adapter. /DEV=XX Selects PCI device of the adapter to program. Must be used with the BUS parameter to specify an adapter. /FUN=XX Selects PCI function of the adapter to program. Must be used with both the BUS and DEV parameters to specify an adapter. Press to continue... /DEVICE= 4 hex digit device id of card to program. /SUBDEVICE= 4 hex digit subsystem device id of card to program. /DUMP Dumps EEPROM/Shadow RAM memory contents to file *.eep and flash memory to *.bin (if available) /MAC_DUMP_FILE Dumps the MAC address to a file usable by the /A command. /MAC_DUMP Displays the adapter LAN MAC address. /MAC_DUMP_ALL Displays all the MAC addresses. /MAC_ALL_TO_FILE Dumps all the MAC addresses to a file usable by the /MAC_ALL_FROM_FILE command. /MAC_ALL_FROM_FILE Programs all MAC addresses from text file to a device. File should contain 13 MAC addresses (9 for PEPs and 4 custom MAC addresses), one each line. EUI48 and EUI64 formats accepted. /CB Clears bits in the EEPROM, specified in . /SB Sets bits in the EEPROM, specified in . Press to continue... /RW Reads from the EEPROM. /WW Writes into in EEPROM. /MAC=macaddr [/NUM=PF_num] Programs the EEPROM/NVM with only the MAC address of macaddr without changing the rest of the EEPROM/NVM. /NUM is optional and I40E specific - it defines target PF. /A or /address Programs the EEPROM/NVM with only the MAC address from the without changing the rest of the EEPROM. /D or /DATA Programs the NVM [EEPROM/FLASH] with the contents of without changing the MAC address. /PHYNVM Programs the PHY NVM with the contents of /DEBUG Forces debug update to be used where applicable. Must be used with /D or /DATA switch. /CALCCHKSUM Forces the EEPROM checksum and CRCs to be updated. Press to continue... /EEPROMVER Displays the version of the EEPROM image. /INVMVERSION Displays the version of the iNVM image. /PCIINFO Displays the PCI information of the adapter. /ADAPTERINFO Displays additional information about the adapter, such as EtrackID, PF MAC address, or image and firmware version. /TEST Checks the EEPROM/NVM checksum(s) and size. /IDFLASH Displays the flash ID and its protected status. /VERSION Displays version and the diagnostic library information. /PHYID Programs the PHY ID NVM with the contents of . /PHYID_DUMP Dumps PHY ID NVM contents to a file with the name: _.bin /PHYID_VERIFY Verifies the PHY ID NVM image in eeprom against the file specified in . Press to continue... /FLASH_DUMP Dumps contents of the whole flash memory of selected adapters to *.bin file /EEPROM_DUMP Dumps contents of the EEPROM/Shadow RAM memory of selected adapters to *.eep file /GUI Brings up GUI mode. /GUI /HELP Displays GUI help. /NOPROT When programming an image for devices that support NVM protection, prevents protection from being enabled. This switch must be used with the /DATA command and has no effect on NVM devices that are already protected. /DEBUGLOG Log debug messages into the debugfile. /VERIFY Verifies the eeprom/NVM image in eeprom/NVM to the target file specified in . Press to continue... /CHECKIMAGE Verifies that the NVM in can be loaded over the running NVM. /VERIFYPHYNVM Verifies the PHY NVM image in eeprom to the target file specified in . /ADAPTERRESET Reset the adapter. *CAUTION* This will unload the driver for this device if present. /SANMAC_DUMP [/NUM=PF_num] Displays the dedicated MAC address for the SAN. /NUM is optional and i40e specific - it defines target PF. /SANMAC=macaddr [/NUM=PF_num] Programs the dedicated SAN MAC address withoutchanging the rest of the EEPROM. /NUM is optional and i40e specific - it defines target PF. /SANADDRESS Programs the dedicated SAN MAC address with the MAC address from . /INVMVERIFY /FILE=] Compares autoload configuration stored in OTP memory with the configuration defined in configuration file. /INVMTEST /FILE=] Report number of free space left in INVM if autoload configuration defined in configuration file would be applied. Press to continue... /INVMUPDATE /FILE=] Write new autoload configuration defined in Raw (*.raw) configuration file to empty INVM or updates current autoload configuration stored in INVM based on 'human readable' configuration file. /INVMISLOCKED Checks if autoload configuration stored in OTP memory is protected against write attempts. /INVMLOCK Sets unique record in autoload configuration stored in INVM protecting its content against further updates. /INVMGET Dumps autoload configuration stored in INVM to file with predefined name .otp. /FORCE Omits any warnings and forces command execution. /KEEPCONFIG This option lets you keep config words while upgrading eeprom. /PORT_MAC=macaddr /NUM=Port_num Programs the dedicated Port MAC address without changing the rest of the EEPROM. /PORT_MAC_DUMP /NUM=Port_num Display the adapter port MAC address. Press to continue... /CUSTOM_MAC mac_number mac_addr Programs the given custom mac address number [0-3] without changing the rest of the NVM (EUI48 and EUI64 formats supported). /SERIAL_MAC=macaddr Programs the dedicated PCIe serial MAC address without changing the rest of the EEPROM. /SERIAL_MAC_DUMP Display the adapter PCIe serial MAC address. /PF_MAC=macaddr /NUM=PF_num Programs the dedicated MAC address of a specified Physical Function This allows altering the mac addresses of inactive functions of a visible NIC. /PF_MAC_DUMP /NUM=PF_num Display MAC address of a selected Physical Function of the specified NIC. This allows dumping MAC addresses of inactive functions of a visible device. /MNG_MAC=macaddr /NUM=MNG_num Programs the dedicated MAC address of a specified Manageability Function This allows altering the mac addresses of inactive functions of a visible NIC. /MNG_MAC_DUMP /NUM=MNG_num Display MAC address of a selected Manageability Function of the specified NIC. This allows dumping MAC addresses of inactive functions of a visible device. /RO Programs RO words in EEPROM/SR with values taken from RO Module binary file.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值