標題:
[基礎題庫] a693 吞食天地
[打印本頁]
作者:
tonyh
時間:
2023-1-13 19:47
標題:
[基礎題庫] a693 吞食天地
本帖最後由 tonyh 於 2023-1-27 20:52 編輯
a693. 吞食天地
本帖隱藏的內容需要回復才可以瀏覽
作者:
李穎俊
時間:
2023-1-13 20:59
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class P1 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str, raw[];
int n, m, sum[];
P1() throws Exception
{
while((str=br.readLine())!=null)
{
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new int[n+1];
raw=br.readLine().split(" ");
for(int i=1; i<=n; i++)
{
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
while(m>0)
{
raw=br.readLine().split(" ");
int l=Integer.parseInt(raw[0]);
int r=Integer.parseInt(raw[1]);
System.out.println(getSum(l, r));
m--;
}
}
}
int getSum(int l, int r)
{
return sum[r]-sum[l-1];
}
public static void main(String[] args) throws Exception{
new P1();
}
}
複製代碼
作者:
陳宥穎
時間:
2023-1-13 21:02
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ch01 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str[];
int n,m,data[],res[];
Ch01() throws Exception
{
while((str=br.readLine().split(" "))!=null)
{
n=Integer.parseInt(str[0]);
m=Integer.parseInt(str[1]);
data=new int[n+1];
res=new int[n+1];
str=br.readLine().split(" ");
for(int i=1; i<=n; i++)
{
int t=Integer.parseInt(str[i-1]);
res[i]=res[i-1]+t;
}
for(int i=0; i<m; i++)
{
str=br.readLine().split(" ");
System.out.println(res[Integer.parseInt(str[1])]-(res[Integer.parseInt(str[0])-1]));
}
}
}
public static void main(String[] args) throws Exception {
new Ch01();
}
}
複製代碼
作者:
洪承廷
時間:
2023-1-13 21:14
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
public class A251 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str,raw[];
int n,m;
long sum[];
A251()throws Exception
{
while((str=br.readLine())!=null){
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new long[n+1];
raw=br.readLine().split(" ");
for(int i=1;i<=n;i++)
{
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
while(m>0)
{
raw=br.readLine().split(" ");
int l=Integer.parseInt(raw[0]);
int r=Integer.parseInt(raw[1]);
System.out.println(getSum(l , r));
m--;
}
}
}
long getSum(int l,int r)
{
return sum[r]-sum[l-1];
}
public static void main(String[] args) throws Exception {
// TODO 自動產生的方法 Stub
new A251();
}
}
複製代碼
作者:
林祐霆
時間:
2023-1-13 21:15
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SUSPECIOUS {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
SUSPECIOUS() throws Exception {
int n, m, l, r;
int sum[];
String str,raw[];
while ((str = br.readLine()) != null) {
raw=str.split(" ");
n = Integer.parseInt(raw[0]);
m = Integer.parseInt(raw[1]);
sum=new int[n+1];
raw = br.readLine().split(" ");
for (int i = 1; i <= n; i++){
int t=Integer.parseInt(raw[i-1]);
sum[i] = sum[i-1]+t;
}
/*
for(int i:sum)
System.out.print(i+" ");
System.out.println();
*/
for(int i=0;i<m;i++){
raw=br.readLine().split(" ");
l = Integer.parseInt(raw[0]);
r = Integer.parseInt(raw[1]);
System.out.println(sum[r]-sum[l-1]);
}
}
}
/*
3 3
1 2 3
1 3
1 2
2 3
*/
public static void main(String[] args) throws Exception {
new SUSPECIOUS();
}
}
複製代碼
作者:
劉愷鈞
時間:
2023-1-27 19:14
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class a693 {
int n,m,sum[],a,b;
String raw[],str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
a693() throws IOException
{
while((str=br.readLine())!=null)
{
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new int[n+1];
raw=br.readLine().split(" ");
for(int i=1;i<=n;i++)
{
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
for(int i=0;i<m;i++)
{
raw=br.readLine().split(" ");
a=Integer.parseInt(raw[0]);
b=Integer.parseInt(raw[1]);
System.out.println(sum[b]-sum[a-1]);
}
}
}
public static void main(String[] args) throws IOException {
new a693();
}
}
複製代碼
作者:
董宸佑
時間:
2023-1-27 19:47
package a693;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class a693 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str, raw[];
int n, m, sum[];
a693() throws IOException{
while((str=br.readLine())!=null) {
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new int[n+1];
raw=br.readLine().split(" ");
for(int i=1; i<=n; i++) {
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
while(m<0) {
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
System.out.println(getSum(n, m));
m--;
}
}
}
int getSum(int l, int r) {
return sum[r]-sum[l-1];
}
public static void main(String[] args) throws Exception {
new a693();
}
}
複製代碼
作者:
李宇澤
時間:
2023-1-27 20:01
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Ch59 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str, raw[];
int n, m, sum[];
Ch59() throws Exception
{
while((str=br.readLine())!=null)
{
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new int[n+1];
raw=br.readLine().split(" ");
for(int i=1; i<=n; i++)
{
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
while(m>0)
{
raw=br.readLine().split(" ");
int l=Integer.parseInt(raw[0]);
int r=Integer.parseInt(raw[1]);
System.out.println(getSum(l, r));
m--;
}
}
}
int getSum(int l, int r)
{
return sum[r]-sum[l-1];
}
public static void main(String[] args) throws Exception{
new Ch59();
}
}
複製代碼
作者:
蘇韋誠
時間:
2023-1-31 17:28
package hahaha;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ha {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str,raw[];
int n,m,sum[];
ha() throws Exception
{
while((str=br.readLine())!=null)
{
raw=str.split(" ");
n=Integer.parseInt(raw[0]);
m=Integer.parseInt(raw[1]);
sum=new int[n+1];
raw=br.readLine().split(" ");
for(int i=1;i<=n;i++)
{
int t=Integer.parseInt(raw[i-1]);
sum[i]=sum[i-1]+t;
}
while(m>0)
{
raw=br.readLine().split(" ");
int l=Integer.parseInt(raw[0]);
int r=Integer.parseInt(raw[1]);
System.out.println(getSum(l,r));
m--;
}
}
}
int getSum(int l,int r)
{
return sum[r]-sum[l-1];
}
public static void main(String[] args) throws Exception {
new ha();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2