代码源div2-record

3.16  Day1

#include <iostream>
using namespace std;
const int N=1e2+5;
int arr[N][N]={0};
bool ans[N][N]={0};
int main()
{
	int sum;cin>>sum;
	for(int i=0;i<=sum/2;i++){
		for(int j=0;j<sum;j++){
			if(ans[i][j]==false)
			{
				ans[i][j]=true;
				if(i%2==0)
				arr[i][j]=1;
				else arr[i][j]=0;
			}
			if(ans[sum-i-1][j]==false)
			{
				ans[sum-i-1][j]=true;
				if(i%2==0)
				arr[sum-i-1][j]=1;
				else arr[sum-i-1][j]=0;
			}	
					
			if(ans[j][i]==false)
			{
				ans[j][i]=true;
				if(i%2==0)
				arr[j][i]=1;
				else arr[j][i]=0;
			}	
			if(ans[j][sum-i-1]==false)
			{
				ans[j][sum-i-1]=true;
				if(i%2==0)
				arr[j][sum-i-1]=1;
				else arr[j][sum-i-1]=0;
			}			
		}
	}
	for(int i=0;i<sum;i++){
		for(int j=0;j<sum;j++){
			if(arr[i][j]==1)cout<<"+";
			else cout<<".";
		}
		cout<<endl;
	}
    return 0;
    
}

#include <iostream>
using namespace std;
const int N=1e2+5;
long long arr[N][3]={0};
int main()
{
	int num;cin>>num;
	arr[1][0]=1;
	arr[2][0]=1;
	arr[2][1]=1;
	for(int i=3;i<=num;i++){
		arr[i][0]=arr[i-1][0]+arr[i-1][1]+arr[i-1][2];
		arr[i][1]=arr[i-2][0];
		arr[i][2]=arr[i-2][1];
	}
	cout<<arr[num][0]+arr[num][1]+arr[num][2];
    return 0;
}

3.20  Day2 

先递归做超时了,后来dp数组范围弄错了

递归wrong:

#include <iostream>
using namespace std;
const int N=1e3+5;
int a[N],b[N];
int n,m;//步数,最右端的位置
int vis[N];
void dfs(int step,int now){
	if(step==n+1)vis[now]=1;
	if(step<=n){
		dfs(step+1,now+a[step]);
		dfs(step+1,now+b[step]);
	}
	
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	dfs(1,0);
	for(int i=0;i<=m;i++)cout<<vis[i];
    return 0;
    
}

dp win: 

#include <iostream>
using namespace std;
const int N=1e5+5;
int a[N],b[N];//每一步可以走几步
int n,m;//步数,最右端的位置
int vis[105][N];//在每一步对应的结果数组
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	vis[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=m;j++){
			if(vis[i][j]==1){
				vis[i+1][j+a[i+1]]=1;
				vis[i+1][j+b[i+1]]=1;
			}
		}
	}
	for(int i=0;i<=m;i++)cout<<vis[n][i];
    return 0;
}

#include <iostream>
using namespace std;
const int N=1e5+5;
struct jishu{
	string id;
	int ans = 0;
};jishu a[N];
struct timu{
	string mingcheng;
	int fenshu;
};timu b[N];
int main()
{	
	int n,m,k;cin>>n>>m>>k;//好朋友的个数,题目的个数,提交的总次数
	for(int i=0;i<n;i++)cin>>a[i].id;//要输出的人物id
	for(int i = 0;i<m;i++) cin >> b[i].mingcheng >> b[i].fenshu;
	string name,title,situation;
	for(int i=0;i<k;i++){
		cin >> name >> title >> situation;
		for(int j = 0;j<n;j++)
		{
			if(name==a[j].id)
			{
				for(int k = 0;k<m;k++)
				{
					if(title==b[k].mingcheng && situation=="AC")
					{
						a[j].ans+=b[k].fenshu;
					}
				}
			}
		}
	}
	for(int i=0;i<n;i++)cout<<a[i].id<<" "<<a[i].ans<<endl;
    return 0;
}

3.21  Day3

#include <iostream>
using namespace std;
int a[6],b[6];
string name[7] = {"FOLD","ROYAL FLUSH","STRAIGHT FLUSH","FOUR OF A KIND","FULL HOUSE","FLUSH","STRAIGHT"};
int main()
{
    for(int i = 1; i<=5; i++) cin >> a[i];
    for(int i = 1; i<=5; i++) cin >> b[i];
    int temp = 0;
    if(a[5]>a[4] && a[4]>a[3] && a[3]>a[2] && a[2]>a[1]) temp = 6;
    if(b[1]==b[2] && b[2]==b[3] && b[3]==b[4] && b[4]==b[5]) temp = 5;
    if(((a[1]==a[2] && a[2]==a[3]) && a[4]==a[5]) || (a[1]==a[2] && (a[3]==a[4] && a[4]==a[5]))) temp = 4;
    if((a[1]==a[2] && a[2]==a[3] && a[3]==a[4]) || (a[2]==a[3] && a[3]==a[4] && a[4]==a[5])) temp = 3;
    if((b[1]==b[2] && b[2]==b[3] && b[3]==b[4] && b[4]==b[5]) && (a[5]-a[4]==1 && a[4]-a[3]==1 && a[3]-a[2]==1 && a[2]-a[1]==1)) temp = 2;
    if(temp==2 && a[5]==14) temp = 1;
    cout << name[temp];
    return 0;
}

 

#include<iostream>
#include<vector>
using namespace std;
vector<int> v;
int main()
{	
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string in;cin>>in;
		if(in=="insert")
		{
			int x,y;cin>>x>>y;
			v.insert(v.begin()+x,y);
		}
		else if(in=="delete")
		{
			int x;cin>>x;
			v.erase(v.begin()+x-1);
		}
		else
		{
			int x;cin>>x;
			cout<<v[x-1]<<endl;
		}
	}
    return 0;
}

#include<iostream>
using namespace std;
int f[1005];int n;
int main()
{	
	cin>>n;
	int a[1005],b[1005],w[1005];
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i]>>w[i];
	}
	for(int i=1;i<=1000;i++){
		f[i]=max(f[i],f[i-1]);
		for(int j=1;j<=n;j++){
			if(a[j]==i){
				f[b[j]]=max(f[b[j]],f[i]+w[j]);
			}	
		}
	}
	cout<<f[1000];
    return 0;
}

 超时的dfs:

#include<iostream>
using namespace std;
const int N=1e2+5;
int a[N][N];
int vis[N][N];
int n,sum;
int xx[5]={0,0,1,-1};
int yy[5]={1,-1,0,0};
void dfs(int x,int y){
	if(x==n&&y==n){
		sum++;
		return;
	}
	for(int i=0;i<4;i++){
		if(x+xx[i]>=1&&x+xx[i]<=n&&y+yy[i]>=1&&y+yy[i]<=n&&a[x+xx[i]][y+yy[i]]==1)
		{
			a[x+xx[i]][y+yy[i]]=0;
			dfs(x+xx[i],y+yy[i]);
			a[x+xx[i]][y+yy[i]]=1;
		}
	}
}
int main()
{	
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
			if(a[i][j]==0)a[i][j]=-1;
		}
	a[1][1]=0;
	dfs(1,1);
	cout<<sum;
    return 0;
}

dp状态转移方程:f(i, j) = f(i - 1, j) + f(i, j - 1) 

#include<iostream>
using namespace std;
const int N=1e2+5;
const int X=1e9+7;
int a[N][N];
int ans[N][N];
int n;
int main()
{	
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	ans[1][1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==1&&j==1)continue;
			if(a[i][j]==0)continue;
			else if(i==1)ans[i][j]=ans[i][j-1];
			else if(j==1)ans[i][j]=ans[i-1][j];
			else ans[i][j]=ans[i-1][j]+ans[i][j-1];
			ans[i][j]%=X;
		}
	}
	cout<<ans[n][n];
    return 0;
}

3.22  Day4

 状态转移方程:ans[i] = max(ans[i], ans[j] + a[i]);

#include<iostream>
using namespace std;
const int N=1e3+5;
int n;int a[N];int ans[N];int maxans;
int main()
{	
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	ans[1]=a[1];
	for(int i=2;i<=n;i++){
		for(int j=1;j<i;j++)
			if(a[i]>a[j])ans[i]=max(ans[i],ans[j]+a[i]);
		ans[i]=max(ans[i],a[i]);
		maxans=max(ans[i],maxans);
	}
	cout<<maxans;
    return 0;
}

 

#include<iostream>
using namespace std;
const int N=1e4+5;
const int mo=1e9+7;
int a[N];
int main()
{	
	int x;cin>>x;
	while(x--){
	int n;cin>>n;//测试单元
	int m;cin>>m;//操作数
	int ll=0;
	while(n>0){
		int j=n%10;
		n/=10;
		a[ll]=j;
		ll++;
	}
	int p=0;
	for(int j=0;j<m;j++){
		for(int i=0;i<ll;i++){
			if(a[i]==9){
				a[i]=1;a[ll]=0;p++;
			}
			else a[i]++;
		}
		if(p!=0){
			ll+=p;
			p=0;
		}
	}
	ll%=mo;
	cout<<ll<<endl;
		
	}
    return 0;
}

3.27 Day5

#include<iostream>
#include<algorithm>
#include<utility>
#include<map>
#include<cmath>
using namespace std;

constexpr int maxn = 501;
//ans为需要的魔法数
int n, ans = 0;
//每个魔法阵的位置
int cx[maxn], cy[maxn];
//存储需要的魔法
map<pair<int, int>, bool> magic;

//获取两点之间传送需要的最小魔法
pair<int, int> getMagic(int p1, int p2)
{
    int x = cx[p2] - cx[p1], y = cy[p2] - cy[p1];
    //由于魔法不能使用负次数,所以两点任意传送需要相反的两个魔法。
    //如果不获取绝对值,则两个魔法就会变成同一个魔法。
    int gcd = abs(__gcd(x, y));
    return make_pair(x / gcd, y / gcd);
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> cx[i] >> cy[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            //在一个魔法阵之间传送
            if (i == j)
            {
                continue;
            }
            //获取最小的魔法
            pair<int, int> m = getMagic(i, j);
            //如果还没有使用过这个魔法,就在map中标记需要这个魔法,并计数
            if (magic.find(m) == magic.end())
            {
                ans++;
                magic.insert(map<pair<int, int>, bool>::value_type(m, true));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

 

#include<iostream>
using namespace std;

//无穷大
constexpr int inf = 0x3f3f3f3f;
int t;

int main()
{
    cin >> t;
    while (t--)
    {
        int n, ans = inf;
        string s;
        cin >> n >> s;
        //循环每一个字符
        for (char c = 'a'; c <= 'z'; c++)
        {
            //开头和结尾的下标,需要删除的字符的个数
            int l = 0, r = n - 1, cnt = 0;
            //逐个判断
            while (l < r)
            {
                //出现不同字符
                if (s[l] != s[r])
                {
                    //删去是当前循环的字符
                    if (s[l] == c)
                    {
                        l++;
                        cnt++;
                        continue;
                    }
                    else if (s[r] == c)
                    {
                        r--;
                        cnt++;
                        continue;
                    }
                    //都不是那么这个字符不行
                    else
                    {
                        cnt = inf;
                        break;
                    }
                }
                //向中间移动
                l++;
                r--;
            }
            //更新答案
            ans = min(ans, cnt);
        }
        cout << (ans == inf ? -1 : ans) << endl; 
    }
    return 0;
}

#include<iostream>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        //原序列和新序列
        string s, s2;
        cin >> s >> s2;
        //长度不同肯定不能转换
        if (s.size() != s2.size())
        {
            cout << "NO" << endl;
            continue;
        }
        //长度都为1时,只需要看两个序列是否相同
        if (s.size() == 1)
        {
            cout << (s[0] == s2[0] ? "YES" : "NO") << endl;
        }
        else
        {
            //原序列1的个数和新序列1的个数
            int o1 = 0, o2 = 0;
            //计数
            for (int i = 0; i < s.size(); i++)
            {
                if (s[i] == '1')
                {
                    o1++;
                }
                if (s2[i] == '1')
                {
                    o2++;
                }
            }
            //原序列全是0而新序列有1
            if(o1 == 0 && o2 > 0)
            {
                cout << "NO" << endl;
            }
            //原序列有1而新序列全是0
            else if(o1 > 0 && o2 == 0)
            {
                cout << "NO" << endl;
            }
            //其他情况都可以
            else
            {
                cout << "YES" << endl;
            }
        }
    }
    return 0;
}

 

#include<cstdio>

constexpr int maxn = 100005;
//栈中元素个数,模拟栈用的数组
int cnt = 0, s[maxn];

//入栈
void push(int number)
{
    s[cnt++] = number;
}

//出栈
void pop()
{
    cnt--;
}

//获取顶部元素
int top()
{
    return s[cnt - 1];
}

//判断栈是否为空
bool empty()
{
    return cnt == 0;
}

int main()
{
    //now为当前要入栈的元素
    int n, t, now = 1;
    scanf("%d", &n);
    //每次循环出栈一次
    for (int i = 1; i <= n; i++)
    {
        //获取出栈序列当前元素
        scanf("%d", &t);
        //顶部元素不为出栈序列当前元素时就入栈
        while (empty() || top() < t)
        {
            push(now);
            printf("push %d\n", now);
            now++;
        }
        //相同就出栈
        if (top() == t)
        {
            pop();
            printf("pop\n");
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是使用 ant-design-vue 组件库中的 a-table 组件来渲染一个表格,具体实现细节如下: - :columns="tableHead":设置表格的列定义,即表头信息,这里使用了 Vue 的属性绑定语法,将父组件中的 tableHead 数组传递给了 a-table 组件的 columns 属性。 - :data-source="tableData":设置表格的数据,即表格中需要展示的数据,这里同样使用了属性绑定语法,将父组件中的 tableData 数组传递给了 a-table 组件的 data-source 属性。 - :pagination=false:设置是否需要分页,默认为 true,这里将其设置为 false。 - bordered:设置是否需要表格边框,默认为 false,这里将其设置为 true。 - :scroll="{x:1000}":设置表格的横向滚动,当表格内容宽度超过 1000px 时出现横向滚动条,这里同样使用了属性绑定语法。 - v-for="col in ['ghrRegular1','ghrShift1']":使用 v-for 指令将表格中需要特殊处理的列(ghrRegular1 和 ghrShift1)进行遍历,方便后续对这些列的处理。 - :slot="col":使用 slot 插槽将遍历到的列对应的数据插入到对应的列中。 - slot-scope="text,record,index":使用 slot-scope 属性获取到 slot 插槽中的三个变量,分别是该单元格的文本内容 text、该单元格所在行的数据 record、以及该单元格所在行的索引 index。 - v-if="record.editable":当该单元格的对应行数据中的 editable 属性为 true 时,显示一个可编辑的 a-input 组件。 - :value="text":将该单元格的文本内容 text 绑定到 a-input 组件的 value 属性上,以显示该单元格的原始内容。 - @change="e => handleChange(e.target.value, record.key, col)":监听 a-input 组件的 change 事件,当用户修改了该单元格的内容时,触发 handleChange 方法,将修改后的内容、该单元格所在行的 key 值以及该单元格对应的列名称 col 作为参数传递给 handleChange 方法。 - <template v-else>:当该单元格的对应行数据中的 editable 属性为 false 时,显示该单元格的原始内容。 - {{ text }}:显示该单元格的原始内容。 - <div slot="index" slot-scope="text,record,index">:使用 slot 插槽将表格中的索引列插入到对应的列中。 - {{ index + 1 }}:显示该单元格所在行的索引 index 加上 1(因为索引从 0 开始)。 - v-for="reg in regularColSlot"/v-for="shi in shiftColSlot":使用 v-for 指令将需要特殊处理的列(regularColSlot 和 shiftColSlot)进行遍历,方便后续对这些列的处理。 - :slot="reg" / :slot="shi":使用 slot 插槽将遍历到的列对应的数据插入到对应的列中。 - slot-scope="text, record":使用 slot-scope 属性获取到 slot 插槽中的两个变量,分别是该单元格的文本内容 text 和该单元格所在行的数据 record。 - <EditableCell :text="text" @change="(val)=>handleEditCellChange(val,record,reg)"/>:渲染一个名为 EditableCell 的子组件,将该单元格的文本内容 text 作为 props 传递给 EditableCell 组件,同时监听 EditableCell 组件的 change 事件,当用户修改了该单元格的内容时,触发 handleEditCellChange 方法,将修改后的内容、该单元格所在行的数据 record,以及该单元格对应的列名称 reg 作为参数传递给 handleEditCellChange 方法。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值