sql判断整除_判断整除 - Ed_Sheeran - 博客园

判断整除

链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1195

时间限制: 1000 ms         内存限制: 65536 KB

【题目描述】

一个给定的正整数序列,在每个数之前都插入+号或-号后计算它们的和。比如序列:1、2、4共有8种可能的序列:

(+1) + (+2) + (+4) = 7

(+1) + (+2) + (-4) = -1

(+1) + (-2) + (+4) = 3

(+1) + (-2) + (-4) = -5

(-1) + (+2) + (+4) = 5

(-1) + (+2) + (-4) = -3

(-1) + (-2) + (+4) = 1

(-1) + (-2) + (-4) = -7

所有结果中至少有一个可被整数k整除,我们则称此正整数序列可被k整除。例如上述序列可以被3、5、7整除,而不能被2、4、6、8……整除。注意:0、-3、-6、-9……都可以认为是3的倍数。

【输入】

输入的第一行包含两个数:N(2

【输出】

如果此正整数序列可被k整除,则输出YES,否则输出NO。(注意:都是大写字母)

【输入样例】

3 2

1 2 4

题解:利用公式(a*b)%c == ((a%c)*(b%c))%c,f[i][j]表示到第i个数的余数是否可为j,只要f[n][0]=1即成立;

对于f[1]只考虑一种分式,因为整体乘-1即可得到另一种,见样例

#include#include#include#include

using namespacestd;bool f[10005][205];int a[10005];intmain()

{intn,k;

cin>>n>>k;for(int i=1;i<=n;i++)cin>>a[i];

f[1][(a[1]%k+k)%k]=1;for(int i=2;i<=n;i++)for(int j=0;j

f[i][j]=(f[i-1][((j-a[i])%k+k)%k]||f[i-1][(j+a[i])%k]);

}if(f[n][0])cout<

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是本地音乐播放器的C语言代码: ``` #include <stdio.h> //定义歌曲结构体 typedef struct song { char name[50]; char artist[50]; char album[50]; } Song; int main() { int option = 0; int volume = 50; int current_song = 0; int num_songs = 3; //设定初始歌曲数 //定义歌曲列表 Song song_list[10]; //添加默认歌曲 strcpy(song_list[0].name, "Shape of You"); strcpy(song_list[0].artist, "Ed Sheeran"); strcpy(song_list[0].album, "Divide"); strcpy(song_list[1].name, "Despacito"); strcpy(song_list[1].artist, "Luis Fonsi ft. Daddy Yankee"); strcpy(song_list[1].album, "Vida"); strcpy(song_list[2].name, "Perfect"); strcpy(song_list[2].artist, "Ed Sheeran"); strcpy(song_list[2].album, "Divide"); //输出菜单选项 printf("Enter an option:\n"); printf("1 - View song list\n"); printf("2 - Play/Pause\n"); printf("3 - Next song\n"); printf("4 - Previous song\n"); printf("5 - Adjust volume\n"); //循环等待用户输入 while (1) { scanf("%d", &option); switch (option) { case 1: printf("Song list:\n"); for (int i = 0; i < num_songs; i++) { printf("%d. %s - %s (%s)\n", i+1, song_list[i].name, song_list[i].artist, song_list[i].album); } printf("Enter a number to select a song:\n"); scanf("%d", &current_song); printf("Now playing: %s - %s (%s)\n", song_list[current_song-1].name, song_list[current_song-1].artist, song_list[current_song-1].album); break; case 2: printf("Play/Pause\n"); break; case 3: printf("Next song\n"); current_song = (current_song + 1) % num_songs; printf("Now playing: %s - %s (%s)\n", song_list[current_song].name, song_list[current_song].artist, song_list[current_song].album); break; case 4: printf("Previous song\n"); current_song = (current_song - 1 + num_songs) % num_songs; printf("Now playing: %s - %s (%s)\n", song_list[current_song].name, song_list[current_song].artist, song_list[current_song].album); break; case 5: printf("Adjust volume (0-100)\n"); scanf("%d", &volume); if (volume < 0) { volume = 0; } if (volume > 100) { volume = 100; } printf("Volume is now %d\n", volume); break; default: printf("Invalid option, try again\n"); break; } } return 0; } ``` 使用方法: 1. 编译运行程序。 2. 在菜单中选择歌曲列表选项,然后从列表中选择歌曲编号。 3. 播放歌曲后,可以使用菜单中的其他选项控制播放器。 举例: 1. 选择歌曲列表选项,输入“1”,然后输入“2”。 2. 暂停歌曲,选择播放/暂停选项(输入“2”)。 3. 下一首歌曲,选择下一曲选项(输入“3”)。 4. 调节音量,选择音量调节选项(输入“5”),然后输入0-100之间的音量值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值