1、题目名称:小Q新式棋盘
时间限制:1000ms内存限制:256M
题目描述
已知棋盘大小为n*n。 每个位置都有自己的权值q。 该棋盘中有多少对行权值和小于列权值和。
输入描述:
第一行输入整数n。(1<=n<=100)表示棋盘的大小 以下n行每行输入n个整数表示棋子的权值。(1<=a<=1000)
输出描述:
输出小Q的分值。
示例
示例1
输入
3
1 2 3
1 2 3
1 2 3
输出
3
#include <stdlib.h>
#include <string.h>
#include<iostream>
#include<vector>
using namespace std;
int n;
int **arr;
void solution() {
int *row=(int*)malloc(sizeof(int)*n);
int *col=(int*)malloc(sizeof(int)*n);
memset(row,0,sizeof(int)*n);
memset(col,0,sizeof(int)*n);
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
row[i]+=arr[i][j];
col[j]+=arr[i][j];
}
}
int s=0;
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
//printf("row:%d col:%d row:%d col:%d\n",i,j,row[i],col[j]);
if(row[i]<col[j]) {
s++;
}
}
}
cout<<s<<endl;
}
int main() {
cin>>n;
arr = (int**)malloc(n * sizeof(int*));
for (int i = 0; i < n; i++) {
arr[i]=(int*)malloc(n * sizeof(int));
for (int j = 0; j < n; j++) {
cin>>arr[i][j];
}
}
solution();
return 0;
}
2、题目名称:Longest Continuous Increasing Subsequence
时间限制:1000ms内存限制:256M
题目描述
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).(Test cases are for reference only, you will be scored by the quality of code.)
输入描述:
Enter the integer n in the first line. Enter n integers in the second line.
输出描述:
Outputs the length of the longest incremental sequence.
示例
示例1
输入
5
1 3 5 4 7
输出
3
class Solution {
public:
int findLengthOfLCIS(vector<int>& nums) {
int len = nums.size(),ans = 1,cur = 1;
if(!len)
return 0;
else{
for(int i = 1;i < len;i ++){
if(nums[i] > nums[i - 1]){
ans = max(ans,++ cur);
}
else{
cur = 1;
}
}
}
return ans;
}
};
3、题目名称:贝博士的机械零件
时间限制:1000ms内存限制:256M
题目描述
贝博士是个大忙人,他在设计和制造一台非常复杂的机械式计算机。 最近贝博士有一点烦恼,因为机械零件的种类繁多,磨损又快,经费不太够用了。不过,他发现有一些机械零件在磨损以后,可以用若干同一型号的磨损旧零件重新回炉熔化以后再铸造出一个该型号的新零件,符合这样的特点的机械零件称为可翻新零件。 于是贝博士请来了他的助手艾小姐,请她统计一下有多少种型号的可翻新零件,每一种目前有多少存量又能以多少个旧零件重新回炉铸造出一个新零件,要求计算出对应于每一种机械零件他最终能使用的零件个数。
输入描述:
第一行输入两个数p和q,表示某型号的零件存量为p,且可以用q个旧零件重新回炉铸造出一个新零件。
输出描述:
每一种可翻新机械零件最终可以使用的个数。
示例
示例1
输入6 6
输出7
#include<bits/stdc++.h>
using namespace std;
int main(){
int p,q,sum=0,m; //p为开始时手中新零件存量,q个旧零件就可以造出一个新零件
cin>>p>>q;
sum = p; //p是要全部使用掉的,直接让sum=p
while(p>=q){
m = p/q; //计算要造出多少个新零件
sum += m; //使用这些新零件
p = p % q; //看余下多少旧零件
p += m; //注意造出的新零件使用后也是旧零件了
}
cout<<sum;
return 0;
}